6

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?

Piotr Findeisen
  • 19,480
  • 2
  • 52
  • 82
wipphd
  • 111
  • 2
  • 4

1 Answers1

16

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

SELECT try(some_array[2]) FROM ...
Piotr Findeisen
  • 19,480
  • 2
  • 52
  • 82