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:
.
,::
- (none)
*
,/
,%
,+
,-
<<
,>>
,<<=
,>>=
||
<
,>
,<=
, `>==
,~
,!=
,<>
,!~
,IN
,BETWEEN
,LIKE
,ILIKE
,WITHIN
&
^
|
AND
,OR
,NOT
See the next section for the current precedence.
Current
operator | name | precedence | description |
---|---|---|---|
. | prefix | 1 | prefix field with table name |
:: | cast | 2 | postgres style type casting |
- | negate | 3 | unary negation of a number |
~ | complement | 3 | unary complement of a number |
* | multiply | 4 | multiply two numbers |
/ | divide | 4 | divide two numbers |
% | modulo | 4 | take the modulo of two numbers |
+ | add | 5 | add two numbers |
- | subtract | 5 | subtract two numbers |
<< | left IPv4 contains strict | 6 | |
>> | right IPv4 contains strict | 6 | |
<<= | left IPv4 contains or equal | 6 | |
<<= | right IPv4 contains or equal | 6 | |
|| | concat | 7 | concatenate strings |
& | bitwise and | 8 | bitwise AND of two numbers |
^ | bitwise xor | 9 | bitwise XOR of two numbers |
| | bitwise or | 10 | bitwise OR of two numbers |
IN | in | 11 | check if value in list or range |
BETWEEN | between | 11 | check if timestamp in range |
WITHIN | within geohash | 11 | prefix matches geohash |
< | lesser than | 12 | lt comparison |
<= | lesser than or equal to | 12 | leq comparison |
> | greater than | 12 | gt comparison |
>= | greater than or equal to | 12 | geq comparison |
= | equals | 13 | eq comparison |
~ | regex match | 13 | regex pattern match |
!= | not equals | 13 | neq comparison |
<> | not equals | 13 | neq comparison |
!~ | regex does not match | 13 | regex pattern does not match |
LIKE | match string | 13 | pattern matching |
ILIKE | match string without case | 13 | case insensitive pattern matching |
NOT | logical not | 14 | logical NOT of two numbers |
AND | logical and | 15 | logical AND of two numbers |
OR | logical or | 16 | logical OR of two numbers |