AWS Athena:将逗号分隔的字符串转换为行

AWS Athena: Convert a comma delimited string into rows

在 AWS Athena 中,我想编写这样的查询:

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

然后回来

row1
row2
row3

我该怎么做?

我知道我可以改写这个,但它对我来说不太方便:

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

您可以使用 split function to convert the string to an array, and then UNNEST 将数组转换为行。例如:

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)