Skip to content
Advertisement

Insert into Nested records in Bigquery

Iam using Bigquery to insert nested records into the table but eventually landed into error scenario.

Schema:

 FieldName                  Type          Mode
 User                       STRING       NULLABLE
 Address                    RECORD       REPEATED
 Address.Name               STRING       NULLABLE
 Address.Age                STRING       NULLABLE
 Address.Details            RECORD       NULLABLE
 Address.Details.line1      STRING       NULLABLE
 Address.Details.line2      STRING       NULLABLE

Code:

INSERT  INTO `<dataset.tablename>`(User, Address)
values('newuser',
   [STRUCT('err' as Name,'24' as Age),
   STRUCT('newerr' as Name,'25' as Age)],
   STRUCT('streetname' as line1),
   STRUCT('houseno.' as line2)
  );

with the above code, I couldn’t able to load the values into table. Please help me by letting know how exactly we can pass values into nested records.

Advertisement

Answer

Try below instead

INSERT  INTO `<dataset.tablename>`(User, Address) values(  
  'newuser', [
  STRUCT('err' as Name,'24' as Age, STRUCT('streetname' as line1, 'houseno.' as line2) as Details),
  STRUCT('newerr' as Name,'25' as Age, STRUCT('streetname' as line3, 'houseno.' as line4))
]
  );
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement