Comparison functions
Compare values and return boolean results.
The comparison functions return 0
or 1
as UInt8
.
The following types can be compared:
- Numbers
- Strings and fixed strings
- Dates
- Dates with times
Only values within the same group can be compared (e.g., UInt16
and UInt64
) but not across groups (e.g., UInt16
and DateTime
).
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” that has another string “S2” as a prefix is considered longer than “S2”.
ClickHouse function reference
equals
Compares two values for equality.
Syntax:
Alternatively, you can use the =
or ==
operators:
Arguments:
a
(any): The first value to compare.b
(any): The second value to compare.
Returns:
1
if the values are equal,0
otherwise. [UInt8
]
Example:
Result:
In this example, equals
checks if each taco’s price is equal to the standard price of 5.99. The result is 1 for tacos with the standard price and 0 for others.
notEquals
Compares two values for inequality.
Syntax:
Alternatively, you can use the !=
or <>
operators:
Arguments:
a
(any): The first value to compare.b
(any): The second value to compare.
Returns:
1
if the values are not equal,0
if they are equal. [UInt8
]
Example:
Result:
In this example, notEquals
checks if each taco’s spice level is different from ‘Medium’. The result is 1 for tacos with spice levels other than ‘Medium’ and 0 for Medium spice level.
less
Compares if the first value is less than the second value.
Syntax:
Alternatively, you can use the <
operator:
Arguments:
a
(any): The first value to compare.b
(any): The second value to compare.
Returns:
1
ifa
is less thanb
,0
otherwise. [UInt8
]
Example:
Result:
In this example, less
checks if each taco’s price is less than 5.00. The result is 1 for tacos priced under 5.00 and 0 for those 5.00 or more.
greater
Compares if the first value is greater than the second value.
Syntax:
Alternatively, you can use the >
operator:
Arguments:
a
(any): The first value to compare.b
(any): The second value to compare.
Returns:
1
ifa
is greater thanb
,0
otherwise. [UInt8
]
Example:
Result:
In this example, greater
checks if each taco’s calorie count is greater than 300. The result is 1 for tacos with more than 300 calories and 0 for those with 300 calories or less.
lessOrEquals
Compares if the first value is less than or equal to the second value.
Syntax:
Alternatively, you can use the <=
operator:
Arguments:
a
(any): The first value to compare.b
(any): The second value to compare.
Returns:
1
ifa
is less than or equal tob
,0
otherwise. [UInt8
]
Example:
Result:
In this example, lessOrEquals
checks if each taco’s preparation time is less than or equal to 5 minutes. The result is 1 for tacos with prep time of 5 minutes or less and 0 for those taking more than 5 minutes.
greaterOrEquals
Compares if the first value is greater than or equal to the second value.
Syntax:
Alternatively, you can use the >=
operator:
Arguments:
a
(any): The first value to compare.b
(any): The second value to compare.
Returns:
1
ifa
is greater than or equal tob
,0
otherwise. [UInt8
]
Example:
Result:
In this example, greaterOrEquals
checks if each taco’s rating is greater than or equal to 4.5. The result is 1 for tacos with ratings of 4.5 or higher and 0 for those with ratings below 4.5.
Was this page helpful?