如何在BigQuery中更新(乘以5,而不是简单地替换)嵌套的收入字段?

时间:2019-07-19 07:24:31

标签: google-bigquery dml

我正在尝试在BigQuery中使用DML更新嵌套的收入字段。 挑战在于,我不想简单地替换收入的价值,而是将其乘以特定的因素。

仅用于替换,我发现:

UPDATE `project.dataset.table`
SET hits = ARRAY(
  SELECT AS STRUCT * REPLACE (
    (SELECT AS STRUCT transaction.* REPLACE ( 1 AS transactionRevenue)) AS transaction
  )
  FROM UNNEST(hits) as transactionRevenue
)
WHERE true

但是我想要类似的东西:

UPDATE `project.dataset.table`
SET hits = ARRAY(
  SELECT AS STRUCT * REPLACE (
    (SELECT AS STRUCT transaction.* REPLACE ( (transactionRevenue*5) AS transactionRevenue)) AS transaction
  )
  FROM UNNEST(hits) as transactionRevenue
)
WHERE true

这种方法行不通。 错误消息:对于运算符*,对于参数类型:STRUCT,INT64没有匹配的签名。支持的签名:INT64 * INT64; FLOAT64 * FLOAT64; NUMERIC * NUMERIC at [4:48]

1 个答案:

答案 0 :(得分:1)

下面应该可以工作

UPDATE `project.dataset.table`
SET hits = ARRAY(
  SELECT AS STRUCT * REPLACE(
    (SELECT AS STRUCT * REPLACE(5 * transactionRevenue AS transactionRevenue) 
      FROM UNNEST([transaction])
    ) AS transaction
  ) 
  FROM t.hits
)
WHERE true