user_1357
user_1357

Reputation: 7940

BigQuery: Create table statement with struct

What is the syntax for creating table statement with struct fields? Below doesn't seem to work. I want to create a Record field such as id.level1.level2.level3.

CREATE TABLE mayumi_load_test.struct_cre(
STRUCT<STRUCT<STRUCT<STRUCT<id INT64> level1> level2>level3,
  t_ TIMESTAMP
)
PARTITION BY Date(t_)

Upvotes: 4

Views: 4735

Answers (1)

Mikhail Berlyant
Mikhail Berlyant

Reputation: 173210

Below is for BigQuery Standard SQL

Create Table

#standardSQL
CREATE TABLE mayumi_load_test.struct_cre (
  id STRUCT<level1 STRUCT<level2 STRUCT<level3 INT64>>>,
  t_ TIMESTAMP
)
PARTITION BY DATE(t_)   

Insert Data

#standardSQL
INSERT INTO mayumi_load_test.struct_cre(id, t_) 
  VALUES(
    STRUCT(STRUCT(STRUCT(777))),
    CURRENT_TIMESTAMP()
  )

Upvotes: 6

Related Questions