【问题标题】:Trying to extract json value from one to many columns on bigquery尝试从 bigquery 的一列到多列中提取 json 值
【发布时间】:2022-01-18 16:10:24
【问题描述】:

我正在尝试为其中一列包含的表格建模:

[{"code": "SEEYOUSOON100", "amount": "250.00", "type": "percentage"}]

[bigquery documentation] 网站的任何解决方案都返回 null。

【问题讨论】:

    标签: json google-bigquery text-extraction


    【解决方案1】:

    考虑以下方法

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-08
      • 1970-01-01
      • 1970-01-01
      • 2021-07-22
      • 2021-08-06
      • 2019-05-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多