Operator Precedence Table

The following tables provide information about which operators are available, and their corresponding precedences.

For IPv4 operators, this list is not comprehensive, and users should refer directly to the IPv4 documentation itself.

Pre-8.0 notice

In QuestDB 8.0.0, operator precedence is aligned closer to other SQL implementations.

If upgrading from 8.0, review your queries for any relevant changes.

If you are unable to migrate straight away, set the cairo.sql.legacy.operator.precedence config option to true in server.conf.

This is a temporary flag which will be removed in succeeding versions of QuestDB.

Legacy precedence, if set, is:

  1. ., ::
  2. (none)
  3. *, /, %, +, -
  4. <<, >>, <<=, >>=
  5. ||
  6. <, >, <=, `>=
  7. =, ~, !=, <>, !~, IN, BETWEEN, LIKE, ILIKE, WITHIN
  8. &
  9. ^
  10. |
  11. AND, OR, NOT

See the next section for the current precedence.

Current

operatornameprecedencedescription
.prefix1prefix field with table name
::cast2postgres style type casting
-negate3unary negation of a number
~complement3unary complement of a number
*multiply4multiply two numbers
/divide4divide two numbers
%modulo4take the modulo of two numbers
+add5add two numbers
-subtract5subtract two numbers
<<left IPv4 contains strict6
>>right IPv4 contains strict6
<<=left IPv4 contains or equal6
<<=right IPv4 contains or equal6
||concat7concatenate strings
&bitwise and8bitwise AND of two numbers
^bitwise xor9bitwise XOR of two numbers
|bitwise or10bitwise OR of two numbers
INin11check if value in list or range
BETWEENbetween11check if timestamp in range
WITHINwithin geohash11prefix matches geohash
<lesser than12lt comparison
<=lesser than or equal to12leq comparison
>greater than12gt comparison
>=greater than or equal to12geq comparison
=equals13eq comparison
~regex match13regex pattern match
!=not equals13neq comparison
<>not equals13neq comparison
!~regex does not match13regex pattern does not match
LIKEmatch string13pattern matching
ILIKEmatch string without case13case insensitive pattern matching
NOTlogical not14logical NOT of two numbers
ANDlogical and15logical AND of two numbers
ORlogical or16logical OR of two numbers