DECLARE

Translation specification for the DECLARE statement from BigQuery to Snowflake

Description

Declares one or more variables of the specified datatype and assigns them the given default value. (BigQuery documentation)

Transformation information

DECLARE variable_name[, ...] [variable_type] [DEFAULT expression];

Sample Source Patterns

Setup data

BigQuery

CREATE TABLE test.declareTable
(
    col1 INT64,
    col2 DATE,
    col3 STRING,
    col4 STRING,
    col5 STRING
);

CREATE TABLE test.declareTable2
(
    col1 ARRAY<INT64>,
    col2 GEOGRAPHY,
    col3 INTERVAL,
    col4 JSON
);

Snowflake

Declare at script level

BigQuery

Snowflake

Declare inside BEGIN...END block

BigQuery

Snowflake

Declare of complex datatype inside BEGIN...END block

BigQuery

Snowflake

Declare of non-literal value at script level

BigQuery

Snowflake

Known Issues

1. Complex datatypes at script level may fail in Snowflake

Declaring variables at script level (outside BEGIN...END blocks) with complex datatypes like ARRAY, GEOGRAPHY or JSON can cause the exception Unsupported feature 'assignment from non-constant source expression' in Snowflake when trying to assign values to the session variable.

The user will be warned of this with an EWI:

Input code:

Expected code:

  1. MSC-BQ0016: Session variable assignment of complex datatype is not supported in Snowflake.

Last updated

Was this helpful?