【问题标题】:REGEXP_EXTRACT with String Value in Google BigqueryREGEXP_EXTRACT 与 Google Bigquery 中的字符串值
【发布时间】:2023-02-02 13:40:11
【问题描述】:

我想将每个部分提取到列中。

Column name: results
Value: {"rID":"09257a3e-f251-4a2e-a63a-ba92c0f86c72","error":{xxx},"num":809}

我的代码:

 select REGEXP_extract(results, r":([0-9]+)") as num 
 from table

我和另一个有问题。

【问题讨论】:

    标签: google-bigquery


    【解决方案1】:

    在下面使用

    create temp function  get_keys(input string) returns array<string> language js as """
      return Object.keys(JSON.parse(input));
      """;
    create temp function  get_values(input string) returns array<string> language js as """
      return Object.values(JSON.parse(input));
      """;
    select * except (results) from (
      select results, key, value
      from your_table, 
      unnest(get_keys(results)) key with offset
      join unnest(get_values(results)) value with offset
      using(offset)
    )
    pivot (any_value(value) for key in ('rID', 'error', 'num'))    
    

    如果应用于您问题中的样本数据 - 输出是

    【讨论】:

      猜你喜欢
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-29
      • 1970-01-01
      • 2015-07-31
      • 1970-01-01
      相关资源
      最近更新 更多