[英]Converting 2 array data type columns into rows in Snowflake
I have a table of two columns both with the array data type.我有一个两列的表,它们都具有数组数据类型。 Their array size is the same (3 elements in an array).
它们的数组大小相同(一个数组中的 3 个元素)。 Each element in an array column is paired with the same-positioned element in another array column.
数组列中的每个元素都与另一个数组列中相同位置的元素配对。 I would like to know how to extract each element in both array columns and convert them into multiple rows using Snowflake.
我想知道如何提取两个数组列中的每个元素并使用 Snowflake 将它们转换为多行。
This is how the table looks like这就是桌子的样子
A header ![]() |
Another header![]() |
---|---|
["a","b","c"] ![]() |
[1,2,3] ![]() |
["d","e","f"] ![]() |
[4,5,6] ![]() |
I want to get the outcome like我想得到这样的结果
characters![]() |
numbers![]() |
---|---|
a![]() |
1 ![]() |
b ![]() |
2 ![]() |
c ![]() |
3 ![]() |
d ![]() |
4 ![]() |
e ![]() |
5 ![]() |
f ![]() |
6 ![]() |
Thank you for the help in advance.提前感谢您的帮助。
You may use FLATTEN for this purpose:您可以为此目的使用 FLATTEN:
select a1.VALUE, a2.VALUE from mytable,
LATERAL FLATTEN( col1 ) a1,
LATERAL FLATTEN( col2 ) a2
where a1.index = a2.index;
+-------+-------+
| VALUE | VALUE |
+-------+-------+
| "a" | 1 |
| "b" | 2 |
| "c" | 3 |
| "d" | 4 |
| "e" | 5 |
| "f" | 6 |
+-------+-------+
FLATTEN https://docs.snowflake.com/en/sql-reference/functions/flatten.html 扁平 https://docs.snowflake.com/en/sql-reference/functions/flatten.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.