wipphd
wipphd

Reputation: 131

INVALID_FUNCTION_ARGUMENT: Array subscript out of bounds

I'm querying a column with a variable length JSON array.

select col.pages[1].name, col.pages[2].name from assoc

I get this error when there is only one value in the array.

INVALID_FUNCTION_ARGUMENT: Array subscript out of bounds

How do I prevent this error if there's only one value?

Upvotes: 7

Views: 11829

Answers (1)

Piotr Findeisen
Piotr Findeisen

Reputation: 20730

Athena is based on Presto 0.172. You can wrap your expression in Presto's try:

SELECT try(some_array[2]) FROM ...

Upvotes: 18

Related Questions