Conditional and miscellaneous functions
TRY_CAST
Reference material for TRY_CAST function
Converts data types into other data types based on the specified parameters. If the conversion cannot be performed, returns a NULL. To return an error message instead, use CAST.
TRY_CAST
replaces only execution errors with NULLs. However, during planning, impossible casts between two non-castable types still produce an error because the query is invalid.
Syntax
Parameters
Parameter | Description | Supported input types |
---|---|---|
<value> | The value to convert or an expression that results in a value to convert | Any |
<type> | The target data type (case-insensitive) | Any |
Return Type
Returns NULL
if the conversion cannot be performed. Otherwise, returns the data type of <type>
.
Example
The following example attempts to cast the level input as an integer:
Returns: 1, null