![](/img/trans.png)
[英]issues converting output from a view to json and array in snowflake using SQL
[英]Getting the index of the JSON array using SQL in Snowflake
我正在使用橫向展平將雪花中的 JSON 數據展平。
我有如下的 JSON 數據:
{
"Fruits": [
{
"Apple_Type" : Type_A,
"Banana_Type": Type_B
},
{
"Apple_Type" : Type_A2,
"Banana_Type": Type_B3
}
]
}
我使用以下查詢來獲取扁平化數據
SELECT v.value:Apple_Type,
v.value:Banana_Type
FROM Table1, LATERAL FLATTEN(input => Fruits) v
我的結果:
--------------------------------
| Apple_Type | Banana_Type |
--------------------------------
| Type_A | Type_B |
| Type_A2 | Type_B3 |
--------------------------------
如何獲取數據的索引。 我想要表格如下
----------------------------------------------
| 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
----------------------------------------------
使用INDEX
:
指數
元素的索引,如果是數組; 否則為 NULL。
SELECT v.value:Apple_Type,
v.value:Banana_Type,
v.index
FROM Table1, LATERAL FLATTEN(input => Fruits) v
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.