Skip to main content

Boolean

The BOOLEAN type represents a statement of truth (true or false).

Boolean Data Types

NameAliasesStorage SizeMin ValueMax ValueDescription
BOOLEANBOOL1 byteLogical boolean (true/false)

Implicit Conversion

Boolean values can be implicitly converted from numeric values to boolean values.

Numeric Conversion:

  • Zero (0) is converted to FALSE.
  • Any non-zero value is converted to TRUE.

String Conversion:

  • Strings converted to TRUE: true
  • Strings converted to FALSE: false
  • Conversion is case-insensitive.
  • All other text strings cannot be converted to Boolean values, it will get Code: 1010 error.

Functions

See Conditional Functions.

Example

SELECT 0::BOOLEAN, 1::BOOLEAN, 'true'::BOOLEAN, 'false'::BOOLEAN, 'True'::BOOLEAN;
+------------+------------+-----------------+------------------+-----------------+
| 0::Boolean | 1::Boolean | 'true'::Boolean | 'false'::Boolean | 'True'::Boolean |
+------------+------------+-----------------+------------------+-----------------+
| 0 | 1 | 1 | 0 | 1 |
+------------+------------+-----------------+------------------+-----------------+

SELECT 'xx'::BOOLEAN;
ERROR 1105 (HY000): Code: 1010, Text = Cast error happens in casting from String to Boolean.
Explore Databend Cloud for FREE
Low-cost
Fast Analytics
Easy Data Ingestion
Elastic Scaling
Try it today