BigQuery 插入嵌套记录
BigQuery Insert into Nested records
我有一个 table 有一个嵌套记录(请参阅附件快照)。
我正在尝试进行简单的插入,但它不起作用。
INSERT INTO `my_project.my_dataset.test_table`(name,address,comments)
values(
'my_name' as name,
[STRUCT('ABC' as line1,'XYZ' as line2,10 as code),
STRUCT('PQR' as line1,'STU' as line2,20 as code)],
'Comment')
知道这个 SQL 插入语句有什么问题吗?
非常感谢您的帮助。
不要在 values
中分配名称。尝试:
INSERT INTO `my_project.my_dataset.test_table`(name,address,comments)
values('my_name',
[STRUCT('ABC' as line1,'XYZ' as line2,10 as code),
STRUCT('PQR' as line1,'STU' as line2,20 as code)],
'Comment'
)
或使用insert . . . select
:
insert into `my_project.my_dataset.test_table`(name,address,comments)
select 'my_name' as name,
[STRUCT('ABC' as line1,'XYZ' as line2,10 as code),
STRUCT('PQR' as line1,'STU' as line2,20 as code)],
'Comment';
考虑将 address
模式更改为 REPEATED
:
另外as name
需要删除:
INSERT INTO `my_project.my_dataset.test_table`(name, address, comments)
values('my_name',
[STRUCT('ABC','XYZ',10), STRUCT('PQR','STU',20)],
'Comment'
)
有什么方法可以使用插入语句在 address.code 中输入数据。例如:
类似的东西:
insert into `my_project.my_dataset.test_table`(name,address.code) select myname,[STRUCT('ABC')] from tab1
我有一个 table 有一个嵌套记录(请参阅附件快照)。
我正在尝试进行简单的插入,但它不起作用。
INSERT INTO `my_project.my_dataset.test_table`(name,address,comments)
values(
'my_name' as name,
[STRUCT('ABC' as line1,'XYZ' as line2,10 as code),
STRUCT('PQR' as line1,'STU' as line2,20 as code)],
'Comment')
知道这个 SQL 插入语句有什么问题吗?
非常感谢您的帮助。
不要在 values
中分配名称。尝试:
INSERT INTO `my_project.my_dataset.test_table`(name,address,comments)
values('my_name',
[STRUCT('ABC' as line1,'XYZ' as line2,10 as code),
STRUCT('PQR' as line1,'STU' as line2,20 as code)],
'Comment'
)
或使用insert . . . select
:
insert into `my_project.my_dataset.test_table`(name,address,comments)
select 'my_name' as name,
[STRUCT('ABC' as line1,'XYZ' as line2,10 as code),
STRUCT('PQR' as line1,'STU' as line2,20 as code)],
'Comment';
考虑将 address
模式更改为 REPEATED
:
另外as name
需要删除:
INSERT INTO `my_project.my_dataset.test_table`(name, address, comments)
values('my_name',
[STRUCT('ABC','XYZ',10), STRUCT('PQR','STU',20)],
'Comment'
)
有什么方法可以使用插入语句在 address.code 中输入数据。例如:
类似的东西:
insert into `my_project.my_dataset.test_table`(name,address.code) select myname,[STRUCT('ABC')] from tab1