- Overview
- Data types
- Commands
- Functions
On this page
Comparison operators
Comparison operators are used to test the equality of two input expressions. They are typically used in the WHERE
clause of a query.
Any value can be compared with another value of the same type. The comparison logics are as follows:
- For boolean values,
true
is greater thanfalse
. - For integer and unsigned integer values, the comparison is natural.
- For floating point values, the comparison is natural, with extra caveats:
NaN
is sorted as greater than all other values and equal to itself, in contradiction with the IEEE standard.+0
is equal to-0
.
- For string values, the comparison is lexicographical.
- For binary values, the comparison is lexicographical on the byte representation.
- For timestamp value, the comparison is natural.
- For interval values, the comparison is natural.
- For array values, the comparison is lexicographical on an element-wise basis.
- For object values, the comparison is lexicographical on the key-value pairs, sorted by keys.
- For any values, if the types of the two values are same, the comparison follows the rules above. If the types are different, the comparison follows the following type order:
- Object > Array > Interval > Timestamp > Boolean > String > Binary > Float > Unsigned Int > Int
- For example, an integer is always less than a string, and a string is always less than an object.
- Any comparison with
NULL
returnsNULL
.
List of comparison operators
Operator | Syntax | Description |
---|---|---|
= | a = b | a is equal to b . |
!= | a != b | a is not equal to b . |
<> | a <> b | a is not equal to b . |
> | a > b | a is greater than b . |
>= | a >= b | a is greater than or equal to b . |
< | a < b | a is less than b . |
<= | a <= b | a is less than or equal to b . |
On this page