Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking array in Athena

I have a table in Athena where one of the columns is of type array<string>. However, when I run

select * from mytable
where array_contains(myarr,'foobar')
limit 10

it seems Athena doesn't have the array_contains function:

SYNTAX_ERROR: line 2:7: Function array_contains not registered

Is there an alternative way to check if the array contains a particular string?

like image 804
dunstantom Avatar asked Apr 12 '17 20:04

dunstantom


People also ask

How do I read an array in Athena?

To access the elements of an array at a given position (known as the index position), use the element_at() function and specify the array name and the index position: If the index is greater than 0, element_at() returns the element that you specify, counting from the beginning to the end of the array.

How do you query an array?

To query if the array field contains at least one element with the specified value, use the filter { <field>: <value> } where <value> is the element value. To specify conditions on the elements in the array field, use query operators in the query filter document: { <array field>: { <operator1>: <value1>, ... } }

How do you create an array in Athena?

To build an array literal in Athena, use the ARRAY keyword, followed by brackets [ ] , and include the array elements separated by commas.


1 Answers

select * 
from   mytable
where  contains(myarr,'foobar')
limit  10
like image 80
David דודו Markovitz Avatar answered Sep 17 '22 23:09

David דודו Markovitz