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 shown below
I need to the update resource.labels which is a repeated record field and has a key value pair resource.labels.key and resource.labels.value on this condition
where key="machinetype" and value="N/A" set value="g1.small"
I have tried this
update `metrics` set resource.labels.value=ARRAY(SELECT AS STRUCT * REPLACE("g1.small" as value) from UNNEST(resource.labels) as h where h.key="machinetype" and h.value="N/A") where resource.labels.key="machinetype" and resource.labels.value="N/A"
but gives this error:
Cannot access field key on a value with type ARRAY<STRUCT<key STRING, value STRING>> at [1:241]
can anyone give any suggestions? Thanks.