Dataphin supports MaxCompute relational, arithmetic, bitwise, and logical operators for use in program code.
Relational operators
Operator | Description |
A=B |
|
A<>B |
|
A<B |
|
A<=B |
|
A>B |
|
A>=B |
|
A IS NULL | Returns TRUE if A is NULL; otherwise, returns FALSE. |
A IS NOT NULL | Returns TRUE if A is not NULL; otherwise, returns FALSE. |
A LIKE B | Returns NULL if either A or B is NULL. Returns TRUE if string A matches pattern B; otherwise, returns FALSE.
|
A RLIKE B | Returns NULL if either A or B is NULL. Returns TRUE if string A matches string constant or regular expression B; otherwise, returns FALSE. Raises an error if B is empty. |
A IN B |
|
BETWEEN AND | The expression is
|
IS [NOT] DISTINCT FROM | The expression is |
Arithmetic operators
Operator | Description |
A+B | Returns NULL if either A or B is NULL; otherwise, returns the sum of A and B. |
A-B | Returns NULL if either A or B is NULL; otherwise, returns the difference between A and B. |
A*B | Returns NULL if either A or B is NULL; otherwise, returns the product of A and B. |
A/B | Returns NULL if either A or B is NULL; otherwise, returns the quotient of A divided by B. Note The return value is of the DOUBLE type when both A and B are BIGINT. |
A%B | Returns NULL if either A or B is NULL; otherwise, returns the remainder of A divided by B. |
+A | Returns A. |
-A | Returns NULL if A is NULL; otherwise, returns the negation of A. |
A DIV B | Returns NULL if either A or B is NULL; otherwise, returns the integer division of A by B. |
Example:
SELECT age+10, age-10, age%10, -age, age*age, age/10, age div 10 FROM user;Arithmetic operations support only STRING, BIGINT, DOUBLE, and TIMESTAMP_NTZ types. BOOLEAN and date types are not supported. For more information on the TIMESTAMP_NTZ data type, see TIMESTAMP_NTZ data type.
STRING values are implicitly converted to DOUBLE before arithmetic operations.
In arithmetic operations involving BIGINT and DOUBLE types, the BIGINT value is implicitly converted to DOUBLE, and the result is of type DOUBLE.
If both A and B are BIGINT, A/B returns a DOUBLE value. Other arithmetic operations return BIGINT.
Bitwise operators
Operator | Example | Description |
|
| The bitwise AND result of A and B is returned. For example, the result of |
|
| The bitwise OR result of A and B is returned. For example, the result of |
|
| The bitwise NOT result of A is returned. For example, the result of |
|
| The bitwise XOR result of A and B is returned. For example, the result of |
Bitwise operators do not support implicit type conversions. You can use only values of the BIGINT type in bitwise operations.
Logical operators
Operator | Description |
A and B | TRUE and TRUE=TRUE |
TRUE and FALSE=FALSE | |
FALSE and TRUE=FALSE | |
FALSE and FALSE=FALSE | |
FALSE and NULL=FALSE | |
NULL and FALSE=FALSE | |
TRUE and NULL=NULL | |
NULL and TRUE=NULL | |
NULL and NULL=NULL | |
A or B | TRUE or TRUE=TRUE |
TRUE or FALSE=TRUE | |
FALSE or TRUE=TRUE | |
FALSE or FALSE=FALSE | |
FALSE or NULL=NULL | |
NULL or FALSE=NULL | |
TRUE or NULL=TRUE | |
NULL or TRUE=TRUE | |
NULL or NULL=NULL | |
NOT A | If A is NULL, NULL is returned. |
If A is TRUE, FALSE is returned. | |
If A is FALSE, TRUE is returned. |
Logical operators do not support implicit type conversions. You can use only the values of the BOOLEAN type in logical operations.