BOOL

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

  1. > CREATE TABLE bool (a INT PRIMARY KEY, b BOOL, c BOOLEAN);
  1. > SHOW COLUMNS FROM bool;
  1. +-------------+-----------+-------------+----------------+-----------------------+-------------+
  2. | column_name | data_type | is_nullable | column_default | generation_expression | indices |
  3. +-------------+-----------+-------------+----------------+-----------------------+-------------+
  4. | a | INT | false | NULL | | {"primary"} |
  5. | b | BOOL | true | NULL | | {} |
  6. | c | BOOL | true | NULL | | {} |
  7. +-------------+-----------+-------------+----------------+-----------------------+-------------+
  8. (3 rows)
  1. > INSERT INTO bool VALUES (12345, true, CAST(0 AS BOOL));
  1. > SELECT * FROM bool;
  1. +-------+------+-------+
  2. | a | b | c |
  3. +-------+------+-------+
  4. | 12345 | true | false |
  5. +-------+------+-------+

Supported casting and conversion

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

TypeDetails
INTConverts true to 1, false to 0
DECIMALConverts true to 1, false to 0
FLOATConverts true to 1, false to 0
STRING––

See also

Data Types

Was this page helpful?
YesNo