Updating nested array in BigQuery based on value in another column

前端 未结 1 1677
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-27 02:41

I have a problem with BigQuery syntax that I\'m a bit stuck on. I have an entry in a table that has multiple key value pairs as an array and I would like to update only a single

相关标签:
1条回答
  • 2021-01-27 03:14

    Below is for BigQuery Standard SQL

    See corrected version of very yours code

    SET
    event_params = ARRAY(
      SELECT AS STRUCT * REPLACE(
        CASE WHEN event_param.key = 'programName' THEN
          (SELECT AS STRUCT * REPLACE('anonymous' AS string_value) FROM UNNEST([value]))
        ELSE value
       END AS value
      ) 
      FROM UNNEST(event_params) AS event_param 
    )
    

    Also, note - you can remove reference to event_param as in below example

    SET
    event_params = ARRAY(
      SELECT AS STRUCT * REPLACE(
        CASE WHEN key = 'programName' THEN
          (SELECT AS STRUCT * REPLACE('anonymous' AS string_value) FROM UNNEST([value]))
        ELSE value
       END AS value
      ) 
      FROM UNNEST(event_params)  
    )
    
    0 讨论(0)
提交回复
热议问题