I want to update a single value from a repeated record in BigQuery analytics events table.
I have tried going through the following link and have tried to write a query too:
UPDATE `analytics_1212191.events_2020*`
SET event_params = ARRAY(
SELECT AS STRUCT
b.key,
b.value.string_value,
b.value.float_value,
b.value.int_value,
b.value.double_value
FROM UNNEST(event_params) as b
)
I want to update b.value.string_value having key = "xyz". I understand there is NO "where" clause yet for this. But the above query (even at above stage) shows the following error:
Value of type
ARRAY<STRUCT<key STRING, string_value STRING, float_value FLOAT64, ...>>
cannot be assigned to event_params, which has type
ARRAY<STRUCT<key STRING, value STRUCT<string_value STRING, int_value INT64, float_value FLOAT64, ...>>> at [4:20]
Thanks Felipe for the answer, With the above issue fixed, I was able to use the following query for Update
.
I thought I should mention the resulting query if anyone has a better idea or to help future viewers:
UPDATE `analytics.events_test`
SET event_params = ARRAY(
SELECT AS STRUCT
b.key,
STRUCT (
CASE WHEN b.key = "type" and b.value.string_value = "xyz" THEN "abc" ELSE b.value.string_value END,
b.value.int_value,
b.value.float_value,
b.value.double_value
) AS value
FROM UNNEST(event_params) as b
)
WHERE event_name = "app_update"
One pointer though:
The plan was to run it on events table and DML statements aren't supported using wildcard in partitioned tables
Looking at the error message, you're missing a STRUCT:
UPDATE `analytics_1212191.events_2020*`
SET event_params = ARRAY(
SELECT AS STRUCT
b.key,
STRUCT (
b.value.string_value,
b.value.int_value,
b.value.float_value,
b.value.double_value
) AS value
FROM UNNEST(event_params) as b
)
I'm with a similar issue. In my case, in clause WHERE I need specify a value of a record column, like this:
UPDATE project_name.dataset_name.table_name
SET labels = ARRAY( SELECT AS STRUCT "customer", "all" FROM UNNEST(labels) as x ) WHERE labels.value = "poc" ;
But seem not possible in BigQuery. I received this message: "Cannot access field value on a value with type ARRAY<STRUCT<key STRING, value STRING>>". Any suggestion?
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.