简体   繁体   中英

AWS Athena: Convert a comma delimited string into rows

In AWS Athena, I want to write a query like this:

SELECT some_function('row1,row2,row3');

And get back

row1
row2
row3

How do I do this?

I know I can write this instead, but it's less convenient for me:

select * from (values ('row1'), ('row2'), ('row3'))

You can use the split function to convert the string to an array, and then UNNEST to convert the array to rows. For example:

WITH t AS (
    SELECT 'row1,row2,row3' AS data
)
SELECT value
FROM t
CROSS JOIN UNNEST(split(t.data, ',')) as x(value)
 value 
-------
 row1  
 row2  
 row3  
(3 rows)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM