帮助客户。我正在尝试将一个嵌套的BigQuery表复制到另一个嵌套的表中,并遇到以下错误:“语法错误:预期为“)”或“,”,但出现了“。”“
查询:
INSERT INTO `<GCP_PROJECT_NAME>.Test_Tables.Nested_Person_Table2` (id,
first_name,
last_name,
dob,
address.status,
address.address,
address.city,
address.state,
address.zip,
address.numberOfYears)
SELECT
id,
first_name,
last_name,
dob,
address.status,
address.address,
address.city,
address.state,
address.zip,
address.numberOfYears
FROM
`<GCP_PROJECT_NAME>.Test_Tables.Nested_Person_Table`
答案 0 :(得分:3)
下面的答案。希望这也能帮助其他人!
INSERT INTO
`<GCP_PROJECT_NAME>.Test_Tables.Nested_Person_Table2`
(id,
first_name,
last_name,
dob,
addresses)
SELECT
id,
first_name,
last_name,
dob,
ARRAY_AGG(STRUCT(a1.status,
a1.address,
a1.city,
a1.state,
a1.zip,
a1.numberOfYears)) AS addresses
FROM
`<GCP_PROJECT_NAME>.Test_Tables.Nested_Person_Table`,
UNNEST(addresses) AS a1
GROUP BY
id,
first_name,
last_name,
dob