Categories:

Conversion functions

TRY_TO_BOOLEAN¶

A special version of TO_BOOLEAN that performs the same operation (i.e. converts an input expression to a Boolean value), but with error-handling support (i.e. if the conversion cannot be performed, it returns a NULL value instead of raising an error).

For more information, see Error-handling conversion functions.

Syntax¶

TRY_TO_BOOLEAN( <string_expr> )
Copy

Arguments¶

string_expr

A string expression that can be evaluated to a BOOLEAN value.

Returns¶

The data type of the returned value is BOOLEAN.

Usage notes¶

  • Only works for string expressions.

Examples¶

This demonstrates usage of TRY_TO_BOOLEAN:

SELECT TRY_TO_BOOLEAN('True')  AS "T", 
       TRY_TO_BOOLEAN('False') AS "F",
       TRY_TO_BOOLEAN('Oops')  AS "N";
+------+-------+------+
| T    | F     | N    |
|------+-------+------|
| True | False | NULL |
+------+-------+------+
Copy