All Products
Search
Document Center

PolarDB:Operators

Last Updated:Mar 28, 2026

PolarDB-X supports logical, arithmetic, comparison, bitwise, and assignment operators. This page documents each operator type and the operator precedence rules that govern expression evaluation.

On this page:

Logical operators

OperatorDescription
AND, &&Logical AND
NOT, !Logical NOT
||, ORLogical OR
XORLogical XOR

Arithmetic operators

OperatorDescription
/, DIVDivision
%, MODReturns the remainder when one number is divided by another
+Addition
*Multiplication
-Subtraction

Comparison operators

Comparison operators are commonly used in conditional SELECT statements to filter rows. Each comparison returns one of three values:

  • 1 — the comparison is true

  • 0 — the comparison is false

  • NULL — the result is unknown (typically when one or both operands are NULL)

OperatorDescription
=Equal to
<>, !=Not equal to
>Greater than
<Less than
<=Less than or equal to
>=Greater than or equal to
BETWEENTrue if the value is within the range, inclusive: value >= min AND value <= max
NOT BETWEENTrue if the value is outside the range
INTrue if the value is in a set
NOT INTrue if the value is not in a set
<=>NULL-safe equality: returns 1 if both operands are NULL, returns 0 if one operand is NULL
LIKEPattern matching using % and _ wildcards
REGEXP, RLIKEPattern matching using regular expressions
IS NULLTrue if the value is NULL
IS NOT NULLTrue if the value is not NULL
The ordinary equality operator (=) returns NULL when either operand is NULL, which may produce unexpected results in WHERE clauses. Use <=> when comparing columns that may contain NULL values.

Bitwise operators

OperatorDescription
&Bitwise AND
~Bitwise NOT
|Bitwise OR
^Bitwise XOR
<<Left shift
>>Right shift

Assignment operators

PolarDB-X supports the = assignment operator, used primarily in the SET clause of UPDATE statements.

PolarDB-X does not support the := assignment operator.

Operator precedence

The following table lists operators in descending order of precedence (highest first). Operators at the same precedence level are evaluated left to right.

PrecedenceOperatorType
15!Unary (prefix)
14- (unary minus), ~Unary (prefix)
13^Binary
12*, /, %, MODBinary
11+, -Binary
10<<, >>Binary
9&Binary
8|Binary
7= (comparison), <=>, >, >=, <, <=, <>, !=, IS, LIKE, REGEXP, INBinary
6BETWEENTernary
5NOTUnary (prefix)
4AND, &&Binary
3XORBinary
2OR, ||Binary
1= (assignment)Binary

IN and NOT IN precedence

IN and NOT IN have higher precedence than the = comparison operator. The following examples, run on MySQL 5.7.19, demonstrate this behavior. PolarDB-X follows the same precedence rule.

SELECT BINARY 'a' = 'a' IN (1, 2, 3);

Result:

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

The expression is evaluated as BINARY 'a' = ('a' IN (1, 2, 3)), not (BINARY 'a' = 'a') IN (1, 2, 3), because IN has higher precedence than =.

SELECT 1 IN (1, 2, 3) = 'a';

Result:

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

Both queries produce Warning 1292: Truncated incorrect DOUBLE value: 'a'.

MySQL compatibility

PolarDB-X is compatible with MySQL operator syntax with the following exception:

OperatorMySQL supportPolarDB-X support
:= (assignment)SupportedNot supported