首页 > 解决方案 > 如何从嵌套表 BigQuery 在嵌套表中插入数据

问题描述

我有 2 个嵌套表,我想互相插入。

我试试这个:

INSERT INTO table1 ( record.id, record.product.type, record.product.price )
SELECT
 id
 product.type
 product.price
FROM table 2

或这个 :

INSERT INTO table1 ( record.id, record.product )
VALUES (
      STRUCT((select id from table2)),
      STRUCT((select product.type from table2))
  )

BQ警报:

Syntax error: Expected ")" or "," but got "." at [1:62] Learn More about BigQuery SQL Functions. 

但不工作..

表格1

record                      RECORD  NULLABLE    
record.id                   STRING  NULLABLE    
record.product              RECORD  NULLABLE    
record.product.type         STRING  NULLABLE    
record.product.price        FLOAT   NULLABLE    

表 2

id                      STRING  NULLABLE    
product                 RECORD  NULLABLE    
product.type            STRING  NULLABLE    
product.price           FLOAT   NULLABLE    

怎么可能呢?

标签: google-bigquery

解决方案


你可以试试这个:

INSERT INTO table1
SELECT STRUCT(id, STRUCT(productPrice.type, productPrice.price)) FROM table2;

推荐阅读