CAST

functionsupportedCore SQL functions

docs.snowflake.com ↗

Conversion functions

Converts a value of one data type into another data type. The semantics of CAST are the same as the semantics of the corresponding TO_ datatype conversion functions. If the cast is not possible, an error is raised. For more details, see the individual TO_ datatype conversion functions. For more information about data type conversion and the TO_ datatype conversion functions, see Data type conversion. The :: operator provides alternative syntax for CAST.

Syntax

CAST( <source_expr> AS <target_data_type> )
  [ RENAME FIELDS | ADD FIELDS ]

<source_expr> :: <target_data_type>

Parameters

NameRequiredDescription
source_exprrequiredExpression of any supported data type to be converted into a different data type.
target_data_typerequiredThe data type to which to convert the expression. If the data type supports additional properties, such as precision and scale (for numbers/decimals), the properties can be included.
RENAME FIELDSrequiredFor structured OBJECTs, specifies that you want to change the OBJECT to use different key-value pairs. The values in the original object are copied to the new key-value pairs in the order in which they appear. For an example, see Example: Changing the key names in an OBJECT value.
ADD FIELDSrequiredFor structured OBJECTs, specifies that you want to add key-value pairs to the OBJECT. For an example, see Example: Adding keys to an OBJECT value. The values for the newly added keys will be set to NULL. If you want to assign a value to these keys, call the OBJECT_INSERT function instead.

Usage notes

See also