GET

functionsupportedCore SQL functions

docs.snowflake.com ↗

Semi-structured and structured data functions

Extracts a value from an ARRAY or an OBJECT (or a VARIANT that contains an ARRAY or OBJECT). The function returns NULL if either of the arguments is NULL. Note that this function should not be confused with the GET DML command.

Syntax

ARRAY (or VARIANT containing an ARRAY)

GET( <array> , <index> )

GET( <variant> , <index> )

OBJECT (or VARIANT containing an OBJECT)

GET( <object> , <field_name> )

GET( <variant> , <field_name> )

MAP

GET( <map> , <key> )

Parameters

NameRequiredDescription
arrayrequiredAn expression that evaluates to an ARRAY.
indexrequiredAn expression that evaluates to an INTEGER. This specifies the position of the element to retrieve from the ARRAY. The position is 0-based, not 1-based. If the index points outside of the array boundaries, or if the indexed element does not exist (in a sparse array): If array is a semi-structured ARRAY, this function returns NULL. If array is a structured ARRAY, an error occurs.
variantrequiredAn expression that evaluates to a VARIANT that contains either an ARRAY or an OBJECT.
objectrequiredAn expression that evaluates to an OBJECT that contains key-value pairs.
field_namerequiredAn expression that evaluates to a VARCHAR. This specifies the key in a key-value pair for which you want to retrieve the value. field_name must not be an empty string. If object is a structured OBJECT, you must specify a constant for field_name. If object does not contain the specified key: If object is a semi-structured OBJECT, the function returns NULL. If object is a structured OBJECT, an error occurs.
maprequiredAn expression that evaluates to a MAP.
keyrequiredThe key in a key-value pair for which you want to retrieve the value. If map does not contain the specified key, the function returns NULL.

Returns

- The returned value is the specified element of the ARRAY, or the value that corresponds to the specified key of a key-value pair in the OBJECT. - If the input object is a semi-structured OBJECT, ARRAY, or VARIANT value, the function returns a VARIANT value. The data type of the value is VARIANT because: In an ARRAY value, each element is of type VARIANT. - In an OBJECT value, the value in each key-value pair is of type VARIANT. - If the input object is a structured OBJECT, structured ARRAY, or MAP, the function returns a value of the type specified for the object. For example, if the type of the input object is ARRAY(NUMBER), the function returns a NUMBER value.

Usage notes

See also

Referenced by