[英]Getting the index of the JSON array using SQL in Snowflake
I'm flattening a JSON data in snowflake using the Lateral Flatten.我正在使用横向展平将雪花中的 JSON 数据展平。
I have the JSON data as follows:我有如下的 JSON 数据:
{
"Fruits": [
{
"Apple_Type" : Type_A,
"Banana_Type": Type_B
},
{
"Apple_Type" : Type_A2,
"Banana_Type": Type_B3
}
]
}
I used the following query to get the flattened data我使用以下查询来获取扁平化数据
SELECT v.value:Apple_Type,
v.value:Banana_Type
FROM Table1, LATERAL FLATTEN(input => Fruits) v
My Result:我的结果:
--------------------------------
| Apple_Type | Banana_Type |
--------------------------------
| Type_A | Type_B |
| Type_A2 | Type_B3 |
--------------------------------
How do I get the index of the data.如何获取数据的索引。 I want the table as follows
我想要表格如下
----------------------------------------------
| Apple_Type | Banana_Type | Index |
----------------------------------------------
| Type_A | Type_B | 0 | -> Because Apple_Type is from index 0 in the Fruit Array
| Type_A2 | Type_B3 | 1 | -> Because Banana_Type is from index 1 in the Fruit Array
----------------------------------------------
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.