Comparisons
Quick reference
| Operator | Description | Example |
|---|---|---|
|
equals |
|
|
does not equal |
|
|
less than |
|
|
greater than |
|
|
less than or equals |
|
|
greater than or equals |
|
|
contains substring |
|
|
matches regular expression |
|
Total ordering
Totally ordered value types permit all equality and inequality comparison operators (viz. ==, !=, <, <=, >, >=).
Comparisons between values of different value types are only allowed between if those value types are comparable. Comparable value type groups include:
| Group | Value types |
|---|---|
Numeric |
|
String |
|
Date |
|
Datetime |
|
† Only finite double values are allowed in TypeDB.
‡ Values of type datetime-tz are ordered based on the equivalent UTC datetime. The time zone does not affect
the ordering.
Equality only
Values of type boolean or duration can only be compared for equality (i.e. using == / !=).
It may not be obvious why two values of type duration may not be comparable.
P1D (1 day) may be 23, 24, or 25 hours, depending on when the duration is applied, due to daylight saving time.
Thus, the result of comparing it with PT24H (24 hours) is indeterminate.
|
String comparison
string values allow two additional comparison operators.
contains allows for checking if the string on the left-hand side contains the right-hand side string as a substring.
The contains operator performs case-insensitive matching by case-folding unicode strings.
like evaluates whether the string on the left-hand side of the operator matches the regular expression string on the right-hand side. The regular expression must follow the rust regex syntax.