Skip to main content

Boolean

Overview

BOOLEAN (alias BOOL) represents TRUE or FALSE and always uses one byte of storage. Numeric and string inputs automatically coerce to boolean values when possible.

Input TypeConverts to TRUEConverts to FALSENotes
NumericAny non-zero0Negative numbers convert to TRUE.
StringTRUEFALSECase-insensitive; other text fails to cast.

Examples

SELECT
0::BOOLEAN AS zero_is_false,
42::BOOLEAN AS nonzero_is_true,
'True'::BOOLEAN AS string_true,
'false'::BOOLEAN AS string_false;

Result:

┌───────────────┬──────────────────┬───────────────┬────────────────┐
│ zero_is_false │ nonzero_is_true │ string_true │ string_false │
├───────────────┼──────────────────┼───────────────┼────────────────┤
│ false │ true │ true │ false │
└───────────────┴──────────────────┴───────────────┴────────────────┘
-- Casting unsupported text raises an error.
SELECT 'yes'::BOOLEAN;

Result:

ERROR 1105 (HY000): QueryFailed: [1006]cannot parse to type `BOOLEAN` while evaluating function `to_boolean('yes')` in expr `CAST('yes' AS Boolean)`
Try Databend Cloud for FREE

Multimodal, object-storage-native warehouse for BI, vectors, search, and geo.

Snowflake-compatible SQL with automatic scaling.

Sign up and get $200 in credits.

Try it today