Update nested record with where condition in Bigquery

后端 未结 1 1841
刺人心
刺人心 2021-01-16 12:03

I have a bigquery table \'metrics\' which has nested record fields One of the fields is called resource.labels which has key pair values as

相关标签:
1条回答
  • 2021-01-16 12:47

    Try below- should work

    UPDATE `project.dataset.metrics`
    SET resource = (
        SELECT AS STRUCT * REPLACE(
          ARRAY(
            SELECT AS STRUCT key, 
              IF(key='machinetype' and value='N/A', 'g1.small', value) as value
            FROM t.labels
          ) AS labels)
        FROM UNNEST([resource]) t
      )
    WHERE true
    
    0 讨论(0)
提交回复
热议问题