运算符
Contents
运算符#
运算符优先级#
%left "OR"
%left "AND"
%left "XOR"
%left UNARY_NOT_PRECEDENCE // (NOT / !)
%nonassoc "=" "==" "<>" ">" "<" ">=" "<=" "!=" "LIKE" "ILIKE" "RLIKE" "IN" "DISTINCT" "BETWEEN" "IS" "NOT_SPECIAL"
%nonassoc "ESCAPE"
%left "|"
%left "^"
%left "&"
%left "<<" ">>"
%left "+" "-"
%left "||"
%left "*" "/" "DIV" "%" "MOD"
%left UNARY_PRECEDENCE // For all unary operators, +, -, ~
各类运算#
1. 比较运算#
操作符名 |
功能描述 |
---|---|
|
大于 |
|
大于等于 |
|
小于 |
|
小于等于 |
|
不等于 |
|
等于 |
|
介于…和…之间 |
|
在…集合中 |
|
模糊匹配,大小写敏感 |
|
模糊匹配, 大小写不敏感 |
|
正则表达式匹配 |
2. 逻辑运算#
操作符名 |
功能描述 |
---|---|
|
逻辑与 |
|
逻辑或 |
|
逻辑与或 |
|
逻辑非, unary operator |
3. 算术运算#
操作符名 |
功能描述 |
---|---|
|
Modulo |
|
Multiplication |
|
Addition |
|
Subtraction |
|
Float division |
|
Integer division |
|
Unary plus |
|
Unary minus, 只支持数值型操作数-number |
4. 位运算#
操作符名 |
Description |
---|---|
|
Bitwise AND |
|
Bitwise OR |
|
Bitwise XOR |
|
Bitwise NOT, unary operator |
5. 类型运算和函数#
操作符名 |
Description |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
类型间转换兼容情况
Safe: 表示从从原类型转换为目标类型的转换是安全的,不会丢失精度也不会计算异常。例如,从int转成bigint不安全的:
SELECT BIGINT(12345);
-- 12345
Unsafe: 表示从原类型转换为目标类型的转换不安全的,数据转换后可能丢失精度或者发生异常。
SELECT INT(1.2);
-- output 1
X:表示从原类型转换为目标类型的转换是不支持的
src|dist |
bool |
smallint |
int |
float |
int64 |
double |
timestamp |
date |
string |
---|---|---|---|---|---|---|---|---|---|
bool |
Safe |
Safe |
Safe |
Safe |
Safe |
Safe |
UnSafe |
X |
Safe |
smallint |
UnSafe |
Safe |
Safe |
Safe |
Safe |
Safe |
UnSafe |
X |
Safe |
int |
UnSafe |
UnSafe |
Safe |
Safe |
Safe |
Safe |
UnSafe |
X |
Safe |
float |
UnSafe |
UnSafe |
UnSafe |
Safe |
Safe |
Safe |
UnSafe |
X |
Safe |
bigint |
UnSafe |
UnSafe |
UnSafe |
UnSafe |
Safe |
UnSafe |
UnSafe |
X |
Safe |
double |
UnSafe |
UnSafe |
UnSafe |
UnSafe |
UnSafe |
Safe |
UnSafe |
X |
Safe |
timestamp |
UnSafe |
UnSafe |
UnSafe |
UnSafe |
Safe |
UnSafe |
Safe |
UnSafe |
Safe |
date |
UnSafe |
X |
X |
X |
X |
X |
UnSafe |
Safe |
Safe |
string |
UnSafe |
UnSafe |
UnSafe |
UnSafe |
UnSafe |
UnSafe |
UnSafe |
UnSafe |
Safe |
赋值操作符#
操作符名 |
功能描述 |
---|---|
|
赋值 (可用于 SET 语句中 ) |