Skip to content
Advertisement

How to break a row into multiple rows based on a column value in Athena (Presto)?

I have a Athena table that has a column containing array of values. I want to create multiple rows from one row such that the column of array can be changed to contain only 1 value.

E.g. :

Name   Id   PhoneNumber
Josh   123  [1236348475,5323794875]

to look like :

Name   Id   PhoneNumber
Josh   123  1236348475
Josh   123  5323794875

How can I write my query to achieve this?

Advertisement

Answer

I think unnest() does what you want:

select t.name, t.id, u.phonenumber
from t cross join
     unnest(t.phonenumber) u(phonenumber);
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement