This documentation is related to an older version of Firebolt. For the most current documentation, see Firebolt documentation.
TRY_CAST
Similar to CAST
, TRY_CAST
converts data types into other data types based on the specified parameters. If the conversion cannot be performed, TRY_CAST
returns a NULL
. To return an error message instead, use CAST
.
Syntax
TRY_CAST(<value> AS <type>)
Parameter | Description |
---|---|
<value> | The value to convert or an expression that results in a value to convert. Can be a column name, a function applied to a column or another function, or a literal value. |
<type> | The target data type (case-insensitive). |
Example
SELECT TRY_CAST('1' AS INTEGER) as res, TRY_CAST('test' AS INTEGER) as res1;
Returns: 1,null