我在BigQuery
中有一个JSON
数组格式的表列,其中有一个类似于{"role":"SuperAdmin","_id":"abcd","userId":"efgh"}
的行。BigQuery中的此列架构是重复模式。我的目标是提取该列中所有行的userId
值。
我尝试过使用JSON
函数,如json_value
和json_extract
select json_value(column_name, '$.users.userId') as userId, from table_name
但是,得到以下错误:
No matching signature for function JSON_VALUE for argument types: ARRAY<STRING>, STRING. Supported signature: JSON_VALUE(STRING, [STRING]) at [2:3]
请问我该怎么做?
发布于 2022-01-19 13:40:04
因为它是重复的,所以你需要先解开它。
给出了以下示例:
with sample_data as (
select ['{"role":"SuperAdmin","_id":"abcd","userId":"efgh"}','{"role":"SuperAdmin","_id":"abcd","userId":"efgh"}','{"role":"SuperAdmin","_id":"abcd","userId":"efgh"}'] as users
)
select json_value(user, '$.userId') as userId
from sample_data , UNNEST(users) user
回报是:
https://stackoverflow.com/questions/70771327
复制相似问题