我正在尝试编写一个sql查询(在Presto中(,以提取详细信息字段中的可读文本无法获得正确的路径
{
"2177f7f1-0d36-4663-b190-b686ab2d9031":{
"button_name":"No Issue",
"details":{
"2abe85b0-5dee-49be-809f-448444af55c4":"No Issue Due to XYZ"
}
},
"b2a6aba8-abe4-4ded-928f-af96eee675ef":{
"button_name":"No Issue",
"details":{
"b40382f7-bf8a-477a-9f38-126d7d0016c4":"Double Blind Confirmed"
}
}
}
这是我尝试过的,但不起作用SELECT json_extract_scalar(content, '$.details') FROM table
假设示例json是content
列中的json,则可以使用presto的功能将json转换为MAP
,并执行以下操作:
WITH dataset (json_str) AS (
VALUES (JSON ' {
"2177f7f1-0d36-4663-b190-b686ab2d9031":{
"button_name":"No Issue",
"details":{
"2abe85b0-5dee-49be-809f-448444af55c4":"No Issue Due to XYZ"
}
},
"b2a6aba8-abe4-4ded-928f-af96eee675ef":{
"button_name":"No Issue",
"details":{
"b40382f7-bf8a-477a-9f38-126d7d0016c4":"Double Blind Confirmed"
}
}
}')
)
SELECT flatten(
transform(
map_values(cast(json_str as MAP(VARCHAR, JSON))),
j -> map_values(
cast(json_extract(j, '$.details') as MAP(VARCHAR, VARCHAR))
)
)
)
FROM dataset
这将产生下一个输出:
_col0 |
---|
[由于XYZ没有问题,双盲确认] |