STRUCT

Translation specification for the STRUCT datatype from BigQuery to Snowflake

Description

In BigQuery, a container of ordered fields each with a type (required) and field name (optional). See Struct Type.

In Snowflake, OBJECT_CONSTRUCT can be used to emulate the STRUCT behavior, and SnowConvert handles most implementation differences.

Note: Arguments that represent keys within the OBJECT_CONSTRUCT must be the original names of the target STRUCT. Any name specified within a STRUCT expression body will be replaced with the name found in the target STRUCT. Most of the data pattern examples below contain an example of a name that is replaced by the target name.

Sample Source Patterns

Setup data

CREATE OR REPLACE TABLE test.structTypes
(
    COL1 STRUCT,
    COL2 STRUCT<sc2 STRING(10)>,
    COL3 STRUCT<sc3 STRUCT<sc31 INT64, sc32 INT64>>,
    COL4 STRUCT<sc4 ARRAY>,
    COL5 STRUCT<sc5 INT64, sc51 INT64>,
    COL7 STRUCT<sc7 INT64 OPTIONS(description = "A repeated STRING field"), sc71 BOOL>,
    COL8 STRUCT<sc8 INT64 NOT NULL, sc81 BOOL NOT NULL OPTIONS(description = "A repeated STRING field")> );
    
CREATE OR REPLACE TABLE test.tuple_sample (
  COL1 STRUCT<Key1 INT64, Key2 INT64>
);

Insert INT Data Type to STRUCT column

Insert STRING Data Type to STRUCT column

Insert STRUCT Data Type to STRUCT column

Insert ARRAY Data Type to STRUCT column

Insert to selected STRUCT columns

Insert to STRUCT column tuple syntax

Update STRUCT column

Update STRUCT column field

Select from STRUCT column

Select from STRUCT column tuple syntax

STRUCT column comparison expressions

Last updated

Was this helpful?