Operator precedence

2024-04-19 08:42:50  Updated

OceanBase Database supports multiple operators, such as arithmetic operators, bitwise operators, comparison operators, logical operators, date and time operators, concatenation operators, and collation operators.

Overview

The following list shows operators sorted by precedence from high to low. Operators listed in the same row have the same precedence.

COLLATE
!
- (unary minus operator), ~ (unary bitwise NOT operator)
^
*, /, DIV, %, MOD
-, +
<<, >>
&
|
= (comparison), <=>, >=, >, <=, <, <>, !=, IN
BETWEEN,
NOT
AND, &&
XOR
OR, ||
= (assignment), :=

Description

  • The precedence of an equal sign (=) depends on whether it is used as a comparison operator or an assignment operator. A comparison operator has the same precedence as <=>, >=, >, <=, <, <>, and !=. An assignment operator has the same precedence as :=.

  • If operators with equal precedence exist in the same expression, the evaluation is performed from left to right. However, assignment is performed from right to left.

  • The precedence and meaning of the following operators depend on the SQL mode:

    • By default, || is a logical OR operator. If PIPES_AS_CONCAT is enabled, || is the string concatenation, with the precedence between ^ and unary operators.

    • By default, ! has higher precedence than NOT. If HIGH_NOT_PRECEDENCE is enabled, ! and NOT have equal precedence.

Contact Us