Arithmetic Operators
Description
You can use arithmetic operators with one or two parameters to perform negation, addition, subtraction, multiplication, and division on numbers. Some of these operators are also used for arithmetic operations on date and time intervals. The parameters of the operators must be parsed as numeric data types, or any data type that can be implicitly converted to numeric data types.
Unary arithmetic operators return the same data type as the parameter numeric data type. For binary arithmetic operators, Doris will convert the parameters to the appropriate type for computation according to implicit type conversion rules, and return the appropriate type as the result. For specific conversion rules, please refer to the "Type Conversion" section.
Operators
Operators | Purpose | Example |
---|---|---|
+ - | Unary operator. It represents taking the positive or negative value of an expression. Equivalent to 0 + a and 0 - a |
|
+ - | Binary operator. It represents adding or subtracting two expressions. |
|
* | Binary operator. It represents multiplying or dividing two expressions. Special case: when the second argument of division is 0, it returns NULL |
|
DIV | Binary operator. It represents integer division of two expressions. Special case: when the second argument is 0, it returns NULL |
|
% | Binary operator. It represents the remainder of two expressions. Special case: when the second argument is 0, it returns NULL |
|
Usage Notes
In arithmetic expressions:
- Do not use consecutive minus signs
--
to indicate double negation (this is the SQL comment symbol) - Use spaces or parentheses to separate as needed:
-(-5)
or- -5
- For more comment standards, please refer to the "Comments" section