BOOLEAN data type
This page documents the preview version (v2.21). Preview includes features under active development and is for development and testing only. For production, use the stable version (v2024.1). To learn more, see Versioning.
Synopsis
Use the BOOLEAN data type to specify values of either true or false.
Syntax
type_specification ::= BOOLEAN
boolean_literal ::= TRUE | FALSE
Semantics
- Columns of type
BOOLEANcannot be part of thePRIMARY KEY. - Columns of type
BOOLEANcan be set, inserted, and compared. - In
WHEREandIFclause,BOOLEANcolumns cannot be used as a standalone expression. They must be compared with eithertrueorfalse. For example,WHERE boolean_column = TRUEis valid whileWHERE boolean_columnis not. - Implicitly,
BOOLEANis neither comparable nor convertible to any other data types.
Examples
ycqlsh:example> CREATE TABLE tasks (id INT PRIMARY KEY, finished BOOLEAN);
ycqlsh:example> INSERT INTO tasks (id, finished) VALUES (1, false);
ycqlsh:example> INSERT INTO tasks (id, finished) VALUES (2, false);
ycqlsh:example> UPDATE tasks SET finished = true WHERE id = 2;
ycqlsh:example> SELECT * FROM tasks;
id | finished
----+----------
2 | True
1 | False