Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 776
wipphd Avatar asked Jul 13 '26 05:07

wipphd


1 Answers

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

SELECT try(some_array[2]) FROM ...
like image 182
Piotr Findeisen Avatar answered Jul 15 '26 19:07

Piotr Findeisen