Comparison operators

Comparison operators test the equality or ordering of two values. Use them in expressions, including SELECT and WHERE.

Comparisons return boolean, or NULL if either input is NULL. Use IS or IS NOT when NULL values need to compare equal.

Values of the same type compare as follows:

TypeComparison rules
intCompare numeric values.
uintCompare numeric values.
floatCompare numeric values. NaN is greater than all other non-NULL values and equal to itself. +0 and -0 compare equal.
booleanFALSE is less than TRUE.
stringLexicographic comparison of characters.
binaryLexicographic comparison of bytes.
timestampAn earlier timestamp is less than a later timestamp.
intervalCompare signed durations. For example, -2 seconds is less than -1 second.
arrayLexicographic comparison of elements, starting at index 0.
objectLexicographic comparison of key-value pairs, with keys sorted from least to greatest.

Lexicographic comparison uses the first unequal pair of characters, bytes, elements, or key-value pairs to determine which value is less. If one sequence is a prefix of the other, the shorter sequence is less.

any values have a defined order that can be used in ORDER BY. Matching contained types follow the rules above. Different contained types compare by type, from greatest to least:

object > array > interval > timestamp > boolean > string > binary > float > uint > int

In this type ordering, an int value is less than a float value, regardless of their numeric values. See semi-structured data types.

List of comparison operators

OperatorSyntaxDescription
=a = ba is equal to b.
!=a != ba is not equal to b.
<>a <> ba is not equal to b.
>a > ba is greater than b.
>=a >= ba is greater than or equal to b.
<a < ba is less than b.
<=a <= ba is less than or equal to b.