我正在尝试对其中一列包含以下内容的表进行建模:
[{"code": "SEEYOUSOON100", "amount": "250.00", "type": "percentage"}]
来自 [bigquery documentation] 的任何解决方案网站返回 null。
最佳答案
考虑以下方法
select
json_extract_scalar(json, '$.code') as code,
json_extract_scalar(json, '$.amount') as amount,
json_extract_scalar(json, '$.type') as type
from your_table,
unnest(json_extract_array(col)) json
如果应用于问题中的示例数据 - 输出为
您可以使用下面的 cte 来播放/测试上面的内容
with your_table as (
select '[{"code": "SEEYOUSOON100", "amount": "250.00", "type": "percentage"}]' col
)
select
json_extract_scalar(json, '$.code') as code,
json_extract_scalar(json, '$.amount') as amount,
json_extract_scalar(json, '$.type') as type
from your_table,
unnest(json_extract_array(col)) json
关于json - 尝试从bigquery上的一到多列中提取json值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70758809/