Operators
All operators Raft DB reads, grouped by kind, with the precedence table and the assignment operators.
An operator joins or changes values in an expression. This page lists them all and links to the page of each group.
Operators by group#
| Group | Operators | Page |
|---|---|---|
| Arithmetic | + - * / DIV % MOD, unary - and + | Arithmetic and logical operators |
| Comparison | = <=> <> != < <= > >= IS IS NOT BETWEEN IN EXISTS, ANY, SOME, ALL, row comparison | Comparison operators |
| Logical | AND && OR || XOR NOT ! | Arithmetic and logical operators |
| Bit | & | ^ ~ << >> | Bit operators |
| String | LIKE NOT LIKE REGEXP RLIKE NOT REGEXP COLLATE BINARY | String operators |
| JSON | -> ->> MEMBER OF (MySQL dialect only) | JSON operators |
| Assignment | := = (in SET and UPDATE) | below |
| Date | + INTERVAL expr unit, - INTERVAL expr unit | Date and time functions |
Precedence#
From the tightest to the loosest. Operators on one row group left to right.
| Level | Operators |
|---|---|
| 1 | INTERVAL expr unit |
| 2 | COLLATE, BINARY, ->, ->>, MEMBER OF |
| 3 | unary -, +, ~ |
| 4 | ^ |
| 5 | *, /, DIV, %, MOD |
| 6 | -, + |
| 7 | <<, >> |
| 8 | & |
| 9 | | |
| 10 | =, <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, IN, BETWEEN |
| 11 | NOT, ! |
| 12 | AND, && |
| 13 | XOR, OR, || |
| 14 | := |
Differences from MySQL's table: XOR is read at the level of OR; ! is read at the level of NOT; || is always OR; ^ binds tighter than * (as in MySQL). The details are on Expressions and operator precedence. Use parentheses where it matters.
Assignment operators#
SET @var = expr; -- SET: = assigns
SET @var := expr; -- := assigns
SELECT @var := expr; -- := assigns inside a statement and gives the value
UPDATE t SET col = expr; -- in UPDATE ... SET, = assigns= assigns only in SET and in UPDATE ... SET; anywhere else it compares. := assigns to a user variable inside any expression (see Variables). The assignment to a column with := in UPDATE ... SET col := expr is read as well.
Remarks#
- Dialect differences. The JSON operators exist in MySQL only, so the MariaDB dialect does not read them.
||isORin both dialects (MariaDB inPIPES_AS_CONCATmode and in Oracle mode would concatenate; Raft DB does not). - Type of the result. A comparison or a logical operator gives
INT0, 1 orNULL; arithmetic follows Expressions and operator precedence. - Not supported yet:
LIKE ... ESCAPE,SOUNDS LIKE, the full-textMATCH ... AGAINST(FULLTEXTkeys are refused), the case-sensitive effect ofBINARY.
Example#
SELECT 2 + 3 * 4, (2 + 3) * 4, 10 DIV 3, 10 % 3, 5 & 4, 1 << 3, 'a' = 'A', NULL <=> NULL;