BOOLEAN type

Synopsis

BOOLEAN data type is used to specify values of either true or false.

Syntax

  1. type_specification ::= BOOLEAN
  2. boolean_literal ::= TRUE | FALSE

Semantics

  • Columns of type BOOLEAN cannot be part of the PRIMARY KEY.
  • Columns of type BOOLEAN can be set, inserted, and compared.
  • In WHERE and IF clause, BOOLEAN columns cannot be used as a standalone expression. They must be compared with either true or false. For example, WHERE boolean_column = TRUE is valid while WHERE boolean_column is not.
  • Implicitly, BOOLEAN is neither comparable nor convertible to any other data types.

Examples

  1. cqlsh:example> CREATE TABLE tasks (id INT PRIMARY KEY, finished BOOLEAN);
  1. cqlsh:example> INSERT INTO tasks (id, finished) VALUES (1, false);
  1. cqlsh:example> INSERT INTO tasks (id, finished) VALUES (2, false);
  1. cqlsh:example> UPDATE tasks SET finished = true WHERE id = 2;
  1. cqlsh:example> SELECT * FROM tasks;
  1. id | finished
  2. ----+----------
  3. 2 | True
  4. 1 | False

See also