雪花解析 JSON 并添加聚合列

Snowflake parsing JSON and add aggrate column

有一个 json 字段

[
    {'id':'1', 'name':'test1', 'address':'123 Main St'},
    {'id':'1', 'name':'test2', 'address':'1404 Burke St'}
]

这是记录到达的方式,我想解析 json 并添加额外的列,该列将告诉它是第一条记录还是第二条记录

到目前为止我有:

select to_variant(parse_json(column)):id, to_variant(to_json(column)):name, to_variant(to_json(column)):address from the table

但无法添加订单栏目

你能试试这样的吗?

select json.index + 1 record_no, json.value:id id, json.value:name name , json.value:address address from
(
    select parse_json($$ [ {'id':'1', 'name':'test1', 'address':'123 Main St'},
    {'id':'1', 'name':'test2', 'address':'1404 Burke St'} ] $$) c1
),
lateral flatten( parse_json(c1 )) json;

+-----------+-----+---------+-----------------+
| RECORD_NO | ID  |  NAME   |     ADDRESS     |
+-----------+-----+---------+-----------------+
|         1 | "1" | "test1" | "123 Main St"   |
|         2 | "1" | "test2" | "1404 Burke St" |
+-----------+-----+---------+-----------------+