Product SiteDocumentation Site

8.5. Comparison

Atomics can be compared with the usual six comparison operators (equality, non-equality, lower-than, greater-than, lower-or-equal, greater-or-equal), and with the same two-letter symbols as in MongoDB.
Comparison is only possible between two compatible types, otherwise, an error is raised.
Example 8.8. Equality comparison.
1 + 1 eq 2,
1 lt 2
Results:
true
true

null can be compared for equality or inequality to anything - it is only equal to itself so that false is returned when comparing if for equality with any non-null atomic. True is returned when comparing it with non-equality with any non-null atomic.
Example 8.9. Equality and non-equality comparison with null.
1 eq null,
"foo" ne null,
null eq null
Results:
false
true
true

For ordering operators (lt, le, gt, ge), null is considered the smallest possible value (like in JavaScript).
Example 8.10. Ordering comparison with null.
null lt 1
Results:
true

Comparisons and logic operators are fundamental for a query language and for the implementation of a query processor as they impact query optimization greatly. The current comparison semantics for them is carefully chosen to have the right characteristics as to enable optimization.