[英]AWS Athena: Convert a comma delimited string into rows
In AWS Athena, I want to write a query like this:在 AWS Athena 中,我想编写这样的查询:
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.您可以使用split函数将字符串转换为数组,然后使用UNNEST
将数组转换为行。 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.