TRY_TO_NUMBER

functionsupportedCore SQL functions

docs.snowflake.com ↗

Conversion functions

A special version of TO_DECIMAL , TO_NUMBER , TO_NUMERIC that performs the same operation of converting an input expression to a fixed-point number, but has error-handling support so that the function returns NULL if the conversion can’t be performed. These functions are synonymous. For more information, see Error-handling conversion functions.

Syntax

supportedpartialnot supportednot scored

TRY_TO_DECIMAL( <string_expr> [, '<format>' ] [, <precision> [, <scale> ] ] )

TRY_TO_NUMBER( <string_expr> [, '<format>' ] [, <precision> [, <scale> ] ] )

TRY_TO_NUMERIC( <string_expr> [, '<format>' ] [, <precision> [, <scale> ] ] )

Parameters

NameRequiredDescription
string_exprrequiredAn expression of type VARCHAR.
formatoptionalThe SQL format model used to parse the input expr and return. For more information, see SQL format models.
precisionoptionalThe maximal number of decimal digits in the resulting number; from 1 to 38. In Snowflake, precision is not used to determine the number of bytes that are needed to store the number and doesn’t have any effect on efficiency, so the default is the maximum (38).
scaleoptionalThe number of fractional decimal digits (from 0 to precision - 1). 0 indicates no fractional digits (i.e. an integer number). The default scale is 0.

Returns

The function returns a value of type NUMBER with the following defaults: - If the precision isn’t specified, then it defaults to 38. - If the scale isn’t specified, then it defaults to 0. If the conversion can’t be performed or the input is NULL, returns NULL.

Usage notes