Skip to main content

Comparison rules

The comparison functions below return 0 or 1 with type UInt8. Only values within the same group can be compared (e.g. UInt16 and UInt64) but not across groups (e.g. UInt16 and DateTime). Comparison of numbers and strings are possible, as is comparison of strings with dates and dates with times. For tuples and arrays, the comparison is lexicographic meaning that the comparison is made for each corresponding element of the left side and right side tuple/array. The following types can be compared:
  • numbers and decimals
  • strings and fixed strings
  • dates
  • dates with times
  • tuples (lexicographic comparison)
  • arrays (lexicographic comparison)
Strings are compared byte-by-byte. This may lead to unexpected results if one of the strings contains UTF-8 encoded multi-byte characters. A string S1 which has another string S2 as prefix is considered longer than S2.

equals

Introduced in: v1.1.0 Compares two values for equality. Syntax
Arguments
  • a — First value.* - b — Second value.*
Returned value Returns 1 if a is equal to b, otherwise 0 UInt8 Examples Usage example
Query
Response

globalIn

Introduced in: v1.1.0 Same as in, but uses global set distribution in distributed queries. The set is sent to all remote servers. Syntax
Arguments
  • x — The value to check. - set — The set of values.
Returned value Returns 1 if x is in the set, 0 otherwise. UInt8 Examples Basic usage
Query
Response

globalInIgnoreSet

Introduced in: v1.1.0 Same as in, but uses global set distribution in distributed queries. The set is sent to all remote servers. This is the IgnoreSet variant used for type analysis without creating the set. Syntax
Arguments
  • x — The value to check. - set — The set of values.
Returned value Returns 1 if x is in the set, 0 otherwise. UInt8 Examples Basic usage
Query
Response

globalNotIn

Introduced in: v1.1.0 Same as notIn, but uses global set distribution in distributed queries. The set is sent to all remote servers. Syntax
Arguments
  • x — The value to check. - set — The set of values.
Returned value Returns 1 if x is not in the set, 0 otherwise. UInt8 Examples Basic usage
Query
Response

globalNotInIgnoreSet

Introduced in: v1.1.0 Same as notIn, but uses global set distribution in distributed queries. The set is sent to all remote servers. This is the IgnoreSet variant used for type analysis without creating the set. Syntax
Arguments
  • x — The value to check. - set — The set of values.
Returned value Returns 1 if x is not in the set, 0 otherwise. UInt8 Examples Basic usage
Query
Response

globalNotNullIn

Introduced in: v1.1.0 Same as notNullIn, but uses global set distribution in distributed queries. The set is sent to all remote servers. Syntax
Arguments
  • x — The value to check. - set — The set of values.
Returned value Returns 1 if x is not in the set, 0 otherwise. UInt8 Examples Basic usage
Query
Response

globalNotNullInIgnoreSet

Introduced in: v1.1.0 Same as notNullIn, but uses global set distribution in distributed queries. The set is sent to all remote servers. This is the IgnoreSet variant used for type analysis without creating the set. Syntax
Arguments
  • x — The value to check. - set — The set of values.
Returned value Returns 1 if x is not in the set, 0 otherwise. UInt8 Examples Basic usage
Query
Response

globalNullIn

Introduced in: v1.1.0 Same as nullIn, but uses global set distribution in distributed queries. The set is sent to all remote servers. Syntax
Arguments
  • x — The value to check. - set — The set of values.
Returned value Returns 1 if x is in the set, 0 otherwise. UInt8 Examples Basic usage
Query
Response

globalNullInIgnoreSet

Introduced in: v1.1.0 Same as nullIn, but uses global set distribution in distributed queries. The set is sent to all remote servers. This is the IgnoreSet variant used for type analysis without creating the set. Syntax
Arguments
  • x — The value to check. - set — The set of values.
Returned value Returns 1 if x is in the set, 0 otherwise. UInt8 Examples Basic usage
Query
Response

greater

Introduced in: v1.1.0 Compares two values for greater-than relation. Syntax
Arguments
  • a — First value.* - b — Second value.*
Returned value Returns 1 if a is greater than b, otherwise 0 UInt8 Examples Usage example
Query
Response

greaterOrEquals

Introduced in: v1.1.0 Compares two values for greater-than-or-equal-to relation. Syntax
Arguments
  • a — First value.* - b — Second value.*
Returned value Returns 1 if a is greater than or equal to b, otherwise 0 UInt8 Examples Usage example
Query
Response

in

Introduced in: v1.1.0 Checks if the left operand is a member of the right operand set. Returns 1 if it is, 0 otherwise. NULL values in the left operand are skipped (treated as not in the set). Syntax
Arguments
  • x — The value to check. - set — The set of values.
Returned value Returns 1 if x is in the set, 0 otherwise. UInt8 Examples Basic usage
Query
Response

inIgnoreSet

Introduced in: v1.1.0 Checks if the left operand is a member of the right operand set. Returns 1 if it is, 0 otherwise. NULL values in the left operand are skipped (treated as not in the set). This is the IgnoreSet variant used for type analysis without creating the set. Syntax
Arguments
  • x — The value to check. - set — The set of values.
Returned value Returns 1 if x is in the set, 0 otherwise. UInt8 Examples Basic usage
Query
Response

isDistinctFrom

Introduced in: v25.11.0 Performs a null-safe “not equals” comparison between two values. Returns true if the values are distinct (not equal), including when one value is NULL and the other is not. Returns false if the values are equal, or if both are NULL. Syntax
Arguments
  • x — First value to compare. Can be any ClickHouse data type. Any
  • y — Second value to compare. Can be any ClickHouse data type. Any
Returned value Returns true if the two values are different, treating NULLs as comparable:
  • Returns true if x != y.
  • Returns true if exactly one of x or y is NULL.
  • Returns false if x = y, or both x and y are NULL. Bool
Examples Basic usage with numbers and NULLs
Query
Response

isNotDistinctFrom

Introduced in: v23.8.0 Performs a null-safe “equals” comparison between two values. Returns true if the values are equal, including when both are NULL. Returns false if the values are different, or if exactly one of them is NULL. Syntax
Arguments
  • x — First value to compare. Can be any ClickHouse data type. Any
  • y — Second value to compare. Can be any ClickHouse data type. Any
Returned value Returns true if the two values are equal, treating NULLs as comparable:
  • Returns true if x = y.
  • Returns true if both x and y are NULL.
  • Returns false if x != y, or exactly one of x or y is NULL. Bool
Examples Basic usage with numbers and NULLs
Query
Response

less

Introduced in: v1.1.0 Compares two values for less-than relation. Syntax
Arguments
  • a — First value.* - b — Second value.*
Returned value Returns 1 if a is less than b, otherwise 0 UInt8 Examples Usage example
Query
Response

lessOrEquals

Introduced in: v1.1.0 Compares two values for less-than-or-equal-to relation. Syntax
Arguments
  • a — First value.* - b — Second value.*
Returned value Returns 1 if a is less than or equal to b, otherwise 0 UInt8 Examples Usage example
Query
Response

notEquals

Introduced in: v1.1.0 Compares two values for inequality. Syntax
Arguments
  • a — First value.* - b — Second value.*
Returned value Returns 1 if a is not equal to b, otherwise 0. UInt8 Examples Usage example
Query
Response

notIn

Introduced in: v1.1.0 Checks if the left operand is NOT a member of the right operand set. Returns 1 if it is not in the set, 0 otherwise. NULL values in the left operand are skipped. Syntax
Arguments
  • x — The value to check. - set — The set of values.
Returned value Returns 1 if x is not in the set, 0 otherwise. UInt8 Examples Basic usage
Query
Response

notInIgnoreSet

Introduced in: v1.1.0 Checks if the left operand is NOT a member of the right operand set. Returns 1 if it is not in the set, 0 otherwise. NULL values in the left operand are skipped. This is the IgnoreSet variant used for type analysis without creating the set. Syntax
Arguments
  • x — The value to check. - set — The set of values.
Returned value Returns 1 if x is not in the set, 0 otherwise. UInt8 Examples Basic usage
Query
Response

notNullIn

Introduced in: v1.1.0 Checks if the left operand is NOT a member of the right operand set. Unlike notIn, NULL values are not skipped: NULL is compared with set elements, and NULL = NULL evaluates to true. Syntax
Arguments
  • x — The value to check. - set — The set of values.
Returned value Returns 1 if x is not in the set, 0 otherwise. UInt8 Examples Basic usage
Query
Response

notNullInIgnoreSet

Introduced in: v1.1.0 Checks if the left operand is NOT a member of the right operand set. Unlike notIn, NULL values are not skipped: NULL is compared with set elements, and NULL = NULL evaluates to true. This is the IgnoreSet variant used for type analysis without creating the set. Syntax
Arguments
  • x — The value to check. - set — The set of values.
Returned value Returns 1 if x is not in the set, 0 otherwise. UInt8 Examples Basic usage
Query
Response

nullIn

Introduced in: v1.1.0 Checks if the left operand is a member of the right operand set. Unlike in, NULL values are not skipped: NULL is compared with set elements, and NULL = NULL evaluates to true. Syntax
Arguments
  • x — The value to check. - set — The set of values.
Returned value Returns 1 if x is in the set, 0 otherwise. UInt8 Examples Basic usage
Query
Response

nullInIgnoreSet

Introduced in: v1.1.0 Checks if the left operand is a member of the right operand set. Unlike in, NULL values are not skipped: NULL is compared with set elements, and NULL = NULL evaluates to true. This is the IgnoreSet variant used for type analysis without creating the set. Syntax
Arguments
  • x — The value to check. - set — The set of values.
Returned value Returns 1 if x is in the set, 0 otherwise. UInt8 Examples Basic usage
Query
Response
Last modified on June 19, 2026