📣
TiDB Cloud Premium is now in public preview. Unlimited growth, instant elasticity, advanced security for enterprise workloads. Try it out →

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)`

Was this page helpful?