BOOL

On this page Carat arrow pointing down
Warning:
GA releases for CockroachDB v23.1 are no longer supported. Cockroach Labs will stop providing LTS Assistance Support for v23.1 LTS releases on November 13, 2025. Prior to that date, upgrade to a more recent version to continue receiving support. For more details, refer to the Release Support Policy.

The BOOL data type stores a Boolean value of false or true.

Aliases

In CockroachDB, BOOLEAN is an alias for BOOL.

Syntax

There are two predefined named constants for BOOL: TRUE and FALSE (the names are case-insensitive).

Alternately, a boolean value can be obtained by coercing a numeric value: zero is coerced to FALSE, and any non-zero value to TRUE.

  • CAST(0 AS BOOL) (false)
  • CAST(123 AS BOOL) (true)

Size

A BOOL value is 1 byte in width, but the total storage size is likely to be larger due to CockroachDB metadata.

Examples

icon/buttons/copy
> CREATE TABLE bool (a INT PRIMARY KEY, b BOOL, c BOOLEAN);
icon/buttons/copy
> SHOW COLUMNS FROM bool;
  column_name | data_type | is_nullable | column_default | generation_expression |  indices  | is_hidden
--------------+-----------+-------------+----------------+-----------------------+-----------+------------
  a           | INT8      |    false    | NULL           |                       | {primary} |   false
  b           | BOOL      |    true     | NULL           |                       | {primary} |   false
  c           | BOOL      |    true     | NULL           |                       | {primary} |   false
(3 rows)
icon/buttons/copy
> INSERT INTO bool VALUES (12345, true, CAST(0 AS BOOL));
icon/buttons/copy
> SELECT * FROM bool;
+-------+------+-------+
|   a   |  b   |   c   |
+-------+------+-------+
| 12345 | true | false |
+-------+------+-------+

Supported casting and conversion

BOOL values can be cast to any of the following data types:

Type Details
INT Converts true to 1, false to 0
DECIMAL Converts true to 1, false to 0
FLOAT Converts true to 1, false to 0
STRING ––

See also

Data Types


Yes No
On this page

Yes No