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

> CREATE TABLE bool (a INT PRIMARY KEY, b BOOL, c BOOLEAN);

> SHOW COLUMNS FROM bool;
+-------+------+-------+---------+
| Field | Type | Null  | Default |
+-------+------+-------+---------+
| a     | INT  | false | NULL    |
| b     | BOOL | true  | NULL    |
| c     | BOOL | true  | NULL    |
+-------+------+-------+---------+
> INSERT INTO bool VALUES (12345, true, CAST(0 AS BOOL));

> SELECT * FROM bool;
+-------+------+-------+
|   a   |  b   |   c   |
+-------+------+-------+
| 12345 | true | false |
+-------+------+-------+

Supported Casting & 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 ––
Because the SERIAL data type represents values automatically generated CockroachDB to uniquely identify rows, you cannot meaningfully cast other data types as SERIAL values.

See Also

Data Types



Yes No