[英]Getting all the values in json array in snowflake
I have a JSON array as follows:我有一个 JSON 数组,如下所示:
This Json data is in the field called col1
in my_table
此 Json 数据位于
my_table
中名为col1
的字段中
{
"JSON_DATA": {
"ID": 1,
"j_array": ["A","B"]
}
}
Here is my SQL to parse the JSON array:这是我的 SQL 来解析 JSON 数组:
SELECT col1:"JSON_DATA"."ID" as id,
v.value as j_array_values
from my_table, lateral flatten(input => col1."JSON_DATA"."j_array") v
My output is我的 output 是
|-------------|-----------------|
| ID | j_array_values |
|-------------|-----------------|
| 1 | ["A","B"] |
|-------------|-----------------|
| 1 | ["A","B"] |
|-------------------------------|
But I want the output to be like但我希望 output 像
|-------------|-----------------|
| ID | j_array_values |
|-------------|-----------------|
| 1 | "A" |
|-------------|-----------------|
| 1 | "B" |
|-------------------------------|
I have used used the lateral flatten but it didn't work我用过横向压扁,但没有用
Using FLATTEN
:使用
FLATTEN
:
CREATE OR REPLACE TABLE my_table AS
SELECT PARSE_JSON('{"JSON_DATA": {
"ID": 1,
"j_array": ["A","B"]
}
}') AS col1;
SELECT col1:JSON_DATA:ID::INT AS id,
v.value::STRING AS j_array_values
FROM my_table, lateral flatten(input => col1:JSON_DATA:j_array) v;
Output: Output:
+----+----------------+
| ID | j_array_values |
+----+----------------+
| 1 | A |
| 1 | B |
+----+----------------+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.