mat*_*252 4 sql arrays data-structures google-bigquery
我正在寻找一种使用 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)]
Run Code Online (Sandbox Code Playgroud)
所以表格看起来像:
我想以某种方式更新此表并将所有dragon名称更改为cat.
以下是 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3557 次 |
| 最近记录: |