A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.snowflake.com/en/sql-reference/functions/to_boolean below:

Website Navigation


TO_BOOLEAN | Snowflake Documentation

Categories:

Conversion functions

TO_BOOLEAN

Converts the input text or numeric expression to a BOOLEAN value.

See also:

TRY_TO_BOOLEAN

Syntax
TO_BOOLEAN( <string_or_numeric_expr> )

Copy

Arguments
string_or_numeric_expr

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

Returns

Returns a BOOLEAN value or NULL.

Usage notes Examples

The following examples use the TO_BOOLEAN function.

Create a table and insert data:

CREATE OR REPLACE TABLE test_boolean(
  b BOOLEAN,
  n NUMBER,
  s STRING);

INSERT INTO test_boolean VALUES
  (true, 1, 'yes'),
  (false, 0, 'no'),
  (null, null, null);

SELECT * FROM test_boolean;

Copy

+-------+------+------+
| B     |    N | S    |
|-------+------+------|
| True  |    1 | yes  |
| False |    0 | no   |
| NULL  | NULL | NULL |
+-------+------+------+

Convert a text string to a BOOLEAN value:

SELECT s, TO_BOOLEAN(s) FROM test_boolean;

Copy

+------+---------------+
| S    | TO_BOOLEAN(S) |
|------+---------------|
| yes  | True          |
| no   | False         |
| NULL | NULL          |
+------+---------------+

Convert a number to a BOOLEAN value:

SELECT n, TO_BOOLEAN(n) FROM test_boolean;

Copy

+------+---------------+
|    N | TO_BOOLEAN(N) |
|------+---------------|
|    1 | True          |
|    0 | False         |
| NULL | NULL          |
+------+---------------+

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4