我有这样结构的 JSON 文件,我需要使用 AWS Athena 查询此 JSON 以提取
myarray
数组中的某些值。
最终结果应为
userIdentifier
且 enabled
值仅在标题 = zz
的情况下
在这种情况下,那就是
useridentifier, enabled
xyz-123, true
json
{
"userIdentifier":"xyz-123",
"myarray":[
{
"code":"split",
"requiresinput":false,
"categorycode":"strictly_necessary",
"originalrequiresinput":false,
"title":"xx",
"enabled":false
},
{
"code":"zz",
"requiresinput":false,
"categorycode":"zz",
"originalrequiresinput":false,
"title":"zz",
"enabled":true
}
]
}
解决了这个问题,分享给其他人。
对于查询,使用 UNNEST 命令。
with cte1 AS
(
SELECT
useridentifier
,json_extract_scalar(source, '$.enabled') enabled
,"$path" pth
FROM "testdb"."test"
CROSS JOIN UNNEST("testdb"."test"."myArray") AS t1 (source)
where json_extract_scalar(source, '$.title') = 'zz'
)
select
useridentifier
,enabled
, pth
from cte1 c