sql - 在 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)]
所以表格看起来像:
我想以某种方式更新此表并将所有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
推荐阅读
- bash - 带有 for 循环的无效算术运算符(错误标记为“”)
- python - 使用并行运行 html2text
- akka - 有没有办法让一个 Akka 节点知道另一个 Akka 节点是否重新启动
- vba - 尽管计算设置为手动,但在打开工作簿时不会禁用计算
- visual-studio-code - 每次在 VS Code 中打开新的终端窗口时,如何运行一些命令?
- javascript - AWS IoT Core 连接被经过身份验证的 Cognito 用户拒绝,带有附加策略 [MQTT over WSS]
- sql - 使用命令复制在 postgres 中出现变量连接问题
- android - Android Intent Share 无法正常工作
- corda - 使用 network-bootstrapper 生成节点信息需要带有 devMode=false 的证书
- php - 由于 .htaccess,php curl 出现 301 错误