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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With