[英]Update values in struct arrays in BigQuery
I am looking for an easy way to update values inside array of structs using SQL. Let's say we have a table:我正在寻找一种使用 SQL 更新结构数组内部值的简单方法。假设我们有一个表:
CREATE TABLE schema.table
(
date DATE,
weights ARRAY<STRUCT<animal STRING, value FLOAT64>>
)
;
insert into schema.table
select cast('2020-01-01' as date), [('dog', 10.2), ('bird', 0.7), ('dragon', 3.2)]
union all
select cast('2020-01-02' as date), [('dog', 10.3), ('bird', 0.7)]
union all
select cast('2020-01-03' as date), [('dragon', 3.3)]
So the table looks like:所以表格看起来像:
I would somehow like to update this table and change all dragon
names to a cat
.我想以某种方式更新此表并将所有
dragon
名更改为cat
。
Below is for BigQuery Standard SQL以下是 BigQuery 标准 SQL
#standardSQL
UPDATE `project.dataset.table` t
SET weights =
ARRAY(
SELECT AS STRUCT IF(animal = 'dragon', 'cat', animal) animal, value
FROM t.weights
)
WHERE TRUE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.