- Conditional processing
- Filtering data
- Implementing complex logical conditions in queries
-
Support for various data types:
- Integers
- Floating-point numbers
- Nullable values
-
Flexible syntax options:
- Functional syntax (e.g.,
and(a, b)) - Operator syntax (e.g.,
a AND b)
- Functional syntax (e.g.,
ClickHouse function reference
Logical functions perform boolean operations on one or more values.and
Calculates the logical conjunction of two or more values. Syntax:AND operator:
- The
ANDoperator
val1,val2, … (Int,UInt,Float, orNullable): List of at least two values.
0if at least one argument evaluates to falseNULLif no argument evaluates to false and at least one argument is NULL1otherwise
UInt8 or Nullable(UInt8)
Example:
In this example, should_celebrate is true only when it’s Taco Tuesday, there’s guacamole, and more than 3 tacos are available.
or
Calculates the logical disjunction of two or more values. Syntax:- The
ORoperator
val1,val2, … (Int,UInt,Float, orNullable): List of at least two values.
1if at least one argument evaluates to true0if all arguments evaluate to falseNULLif all arguments evaluate to false and at least one argument is NULL
UInt8 or Nullable(UInt8).
Example:
hasProteinOption is true if at least one protein option (carnitas, chicken, or beef) is available.
not
Calculates the logical negation of a value. Syntax:- The Negation operator
!
val(Int,UInt,Float, orNullable): The value.
1ifvalevaluates to false0ifvalevaluates to trueNULLifvalis NULL
UInt8 or Nullable(UInt8).
Example:
isMild is the logical negation of isSpicy.
xor
Calculates the logical exclusive disjunction of two or more values. For more than two input values, the function first xor-s the first two values, then xor-s the result with the third value, and so on. Syntax:val1,val2, … (Int,UInt,Float, orNullable): List of at least two values.
- For two values:
1if one of the values evaluates to false and the other does not0if both values evaluate to false or both true
NULLif at least one of the inputs is NULL
UInt8 or Nullable(UInt8).
Example:
hasUniqueTopping is true if exactly one of salsa, guacamole, or sour cream is present on the taco.
not
Calculates the logical negation of a value. Syntax:val(Int,UInt,Float, orNullable): The value to negate.
1ifvalevaluates to false0ifvalevaluates to trueNULLifvalis NULL
UInt8 or Nullable(UInt8)
Example:
not(1)returns 0 because 1 is considered truenot(0)returns 1 because 0 is considered falsenot(NULL)returns NULLnot(isHot('jalapeño'))returns 0, assuming jalapeños are considered hot
The
not function treats any non-zero value as true and zero as false. This applies to all numeric types, including floating-point numbers.