Operator
Contents
Operator#
Operator Precedence#
%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, +, -, ~
Comparison Operation#
operator name |
function description |
---|---|
|
Greater than |
|
Greater than or equal to |
|
Less than |
|
Less than or equal to |
|
Not equal to |
|
Equal |
|
Between left and right |
|
In the collection |
|
Comparison, case sensitive |
|
Comparison, case insensitive |
|
Regular expression comparison |
Logic Operation#
operator name |
function description |
---|---|
|
Logical and |
|
Logical or |
|
Logical xor |
|
Logical not, unary operator |
Arithmetic Operations#
operator name |
function description |
---|---|
|
Modulo |
|
Multiplication |
|
Addition |
|
Subtraction |
|
Float division |
|
Integer division |
|
Unary plus |
|
Unary minus, support only |
Bit Operation#
operator name |
Description |
---|---|
|
Bitwise AND |
|
Bitwise OR |
|
Bitwise XOR |
|
Bitwise NOT, unary operator |
Type Operations and Functions#
operator name |
Description |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Conversion Compatibility Between Types
Safe: Indicates that the conversion from the original type to the target type is safe without loss of precision and no computation exceptions. For example, converting from int to bigint is unsafe:
SELECT BIGINT(12345);
-- 12345
Unsafe: Indicates that the conversion from the original type to the target type is unsafe, and the precision may be lost or an exception may occur after data conversion.
SELECT INT(1.2);
-- output 1
X:Indicates that a conversion from the original type to the target type is not supported
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 |
assignment operator#
operator name |
function description |
---|---|
|
Assignment (can be used in SET statement) |
Conditional Expressions#
CASE Expression#
```sql
SELECT case 'bb' when 'aa' then 'apple' else 'nothing' end; -- SIMPLE CASE WHEN
SELECT case
when 'bb'='aa' then 'apple'
when 'bb'='bb' then 'banana'
else 'nothing' end; -- SEARCHED CASE WHEN
```