更新第 3 级嵌套 Table 以追加记录

Update 3rd level Nested Table to append a record

根据 https://cloud.google.com/bigquery/sql-reference/dml-syntax 中的示例,我们提出了一种可以更新 table (specifications.dimensions) 第 3 级的方法:

UPDATE sd97dwo.DetailedInventory
SET specifications.dimensions = 
    STRUCT<depth FLOAT64, height FLOAT64, width FLOAT64>(1, 2, 3)
WHERE 
    product like '%washer%'
    AND EXISTS(select 1 from unnest(comments) as c where c.comment like '%comment%')

我们现在要做的是更新 table 以将记录附加到相同的维度结构。然而,我们尝试的各种方式都没有成功。想看看是否有人有任何想法。我们得到的最接近的是下面的,但是当然 returns specifications.dimensions 的所有记录(作为多个结果)所以我们得到错误 "Scalar subquery produced more than one element"

UPDATE sd97dwo.DetailedInventory
SET specifications.dimensions
    = (SELECT specifications.dimensions
    UNION ALL
    SELECT STRUCT<depth FLOAT64, height FLOAT64, width FLOAT64>(4.0,5.0,6.0))
WHERE 
    product like '%washer%'
    AND EXISTS(select 1 from unnest(comments) as c where c.comment like '%comment%')

What we are trying to do now, is update the table to APPEND a record to that same dimensions struct.

你的模式是什么? 如果您使用与 DML 文档中相同的架构,那么 "specifications" 和 "dimensions" 都不是重复字段。所以你不能附加到它。但是您可以直接更新它们,例如:

UPDATE sd97dwo.DetailedInventory
SET specifications.dimensions.depth = 1,
     specifications.dimensions.height = 2,
     specifications.dimensions.width = 3
WHERE 
    product like '%washer%'
    AND EXISTS(select 1 from unnest(comments) as c where c.comment like '%comment%')