0

I have 2 Nested Tables and I want to INSERT INTO each other.

I try this :

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

or this :

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

BQ alert :

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

But don't works ..

table 1

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

table 2

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

How can do that ?

2 Answers 2

1

You can try this:

INSERT INTO table1
SELECT STRUCT(id, STRUCT(productPrice.type, productPrice.price)) FROM table2;
Sign up to request clarification or add additional context in comments.

1 Comment

Please consider voting up and accepting this answer if it helped !
0

you can use the APPLY operator to unpivot a table please visit this answer https://stackoverflow.com/a/27708046/1862306

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.