我有这个样本数据(来自雅典娜)
SELECT DISTINCT m.key
FROM (VALUES JSON '{"name":"project1","completed":false}', JSON '{"name":"project1","completed":false}',JSON '{"name":"project1","completed":false}')
example_table(json_column)
CROSS JOIN UNNEST (map_keys(CAST(json_column AS map<varchar,json>))) AS m(key);
WITH dataset AS (
SELECT '{"name": "Susan Smith",
"org": "engineering",
"projects": [{"name":"project1", "completed":false},
{"name":"project2", "completed":true}]}'
AS blob
)
select * from dataset
这将生成以下输出。
{"name": "Susan Smith", "org": "engineering", "projects": [{"name":"project1", "completed":false}, {"name":"project2", "completed":true}]}
我想从输出中提取密钥。
预期产出:
output
------
name
org
projects
有人可以帮忙吗?
更新:
使用适当的 JSON 编辑了这个问题。
根据评论中的讨论,这
map_keys(CAST(json_column AS map<varchar,json>))
需要替换为
map_keys(CAST(CAST(json_column AS JSON) AS map<varchar,json>))