Tuesday, 25 August 2026

Logical Operators in ClickHouse

  

An operator is a symbol or function that performs an operation on one or more values. Logical operators evaluate boolean expressions (true/false, or 1/0 in ClickHouse) and return a result based on logic (like AND, OR, NOT).

 

Following table summarizes the logical operators.

Operator

Function Form

Description

NOT a

not(a)

Logical NOT, inverts the boolean value.

a AND b

and(a, b)

Logical AND, true if both a and b are true

a OR b

or(a, b)

Logical OR, true if either a or b is true

 

Examples

SELECT NOT 1;          -- returns 0 (NOT true)
SELECT NOT 0;          -- returns 1 (NOT false)

SELECT not(1);         -- returns 0
SELECT not(0);         -- returns 1

SELECT 1 AND 1;        -- returns 1 (true AND true)
SELECT 1 AND 0;        -- returns 0 (true AND false)
SELECT 0 AND 1;        -- returns 0 (false AND true)
SELECT 0 AND 0;        -- returns 0 (false AND false)

SELECT and(1, 1);      -- returns 1
SELECT and(1, 0);      -- returns 0

SELECT 1 OR 1;         -- returns 1 (true OR true)
SELECT 1 OR 0;         -- returns 1 (true OR false)
SELECT 0 OR 1;         -- returns 1 (false OR true)
SELECT 0 OR 0;         -- returns 0 (false OR false)

SELECT or(1, 0);       -- returns 1
SELECT or(0, 0);       -- returns 0

   

Previous                                                    Next                                                    Home

No comments:

Post a Comment