简体   繁体   中英

Update ARRAY IN ARRAY BigQuery (GA4 Data)

I want to update a value in array with a value in another table.

table1:

event_params.key event_params.value.string_value
country US

table2:

country new_country
US NL

I try

UPDATE table1

SET event_params = ARRAY(SELECT AS STRUCT * REPLACE ( new_country AS value.string_value ) FROM UNNEST(event_params) 
WHERE key = "country")

FROM(SELECT country, new_country FROM table2)

WHERE 
(SELECT value.string_value from unnest(event_params) where key = 'country') = t2.country

It doesnt work.. The problem is the value.string_value because is also an array.

The final table should look like table1:

event_params.key event_params.value.string_value
country NL

Now I want to update table1 with table2 to udate the country from US to NL in table1.

How can I take the array in array?

I also saw this code:

UPDATE `project.dataset.your_table` t
SET hits = 
  ARRAY(
    SELECT AS STRUCT * REPLACE(
      ARRAY(
        SELECT AS STRUCT product.* REPLACE(
          CASE WHEN map.raw_name = product.productCategory THEN category 
            ELSE productCategoryAttribute END AS productCategoryAttribute)
        FROM UNNEST(product) product
        LEFT JOIN UNNEST(agg_map.map) map 
        ON map.raw_name = product.productCategory
      ) AS product)
    FROM UNNEST(hits) hit
  ) 
FROM (SELECT ARRAY_AGG(row) map FROM `project.dataset.map` row) agg_map 
WHERE TRUE  

BigQuery UPDATE nested array field But I cant implement it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM