Operator precedence

This topic describes the precedence of operators in PolarDB-X.

The following table describes the precedence of operators that are supported by PolarDB-X. The operators are listed by precedence in descending order.

Precedence Operator
15 !
14 - (unary minus) and ~
13 \^
12 *, /, %, and MOD
11 + and -
10 <<,>>
9 &
8 |
7 = (comparison operator), <=>, >, >=, <, <=, <>, !=, IS, LIKE, REGEXP, and IN
6 BETWEEN
5 NOT
4 AND, \&\&
3 XOR
2 OR, ||
1 = (assignment operator)

Note

This section provides sample code to describe whether the IN and NOT IN operators have higher precedence than the equality (=) comparison operator.

Execute the following SQL statements on a database that runs MySQL 5.7.19:

mysql> select binary 'a' = 'a' in (1, 2, 3);
+-------------------------------+
| binary 'a' = 'a' in (1, 2, 3) |
+-------------------------------+
|                             1 |
+-------------------------------+
1 row in set, 1 warning (0.01 sec)

mysql> show warnings;
+---------+------+---------------------------------------+
| Level   | Code | Message                               |
+---------+------+---------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: 'a' |
+---------+------+---------------------------------------+
1 row in set (0.00 sec)

mysql> select 1 in (1, 2, 3) = 'a';
+----------------------+
| 1 in (1, 2, 3) = 'a' |
+----------------------+
|                    0 |
+----------------------+
1 row in set, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+---------------------------------------+
| Level   | Code | Message                               |
+---------+------+---------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: 'a' |
+---------+------+---------------------------------------+
1 row in set (0.00 sec)

The returned result shows that the IN and NOT IN operators have higher precedence than the equality (=) comparison operator in MySQL. The SQL statements in PolarDB-X are executed based on the same precedence rule. Operators of the same precedence are evaluated in order from left to right.

results matching ""

    No results matching ""