如何在BQ中更新struct数组中的字段?

时间:2018-06-01 11:04:41

标签: google-bigquery

在示例中,我可以更新字段“name”,但我无法更新struct数组中的字段“city”。

Error: Cannot access field city on a value with type ARRAY<STRUCT<status STRING, city STRING, state STRING>> at [4:75]

我收到此错误,

    content = {
        "_url": "https://my-example.site/REST/2.0/ticket/2",
        "ref":  "depended-on-by",
        "id":   "2",
        "type": "ticket"
        }
    req = requests.put("path/to/ticket/1/in/api", auth=(user,pass), json=content)

2 个答案:

答案 0 :(得分:3)

   
#standardSQL
UPDATE `mydataset.struct_3` SET address = ARRAY(
  SELECT AS STRUCT 
    status, IF(city="some_city", "some_uscity", city) city, state 
  FROM UNNEST(address)
) WHERE TRUE

答案 1 :(得分:1)

您需要替换数组本身,更新所需的值:

update  `mydataset.struct_3`
set address = ARRAY(SELECT IF(city="some_city", "some_uscity", city) FROM UNNEST(address))