GBase 8a MPP Cluster supports common arithmetic operators. There are two points to note when using them:
- If both parameters are integers, the
-
,+
, and*
operations are performed withBIGINT
(64-bit) precision, and the result is returned. - If one parameter is an unsigned integer and the other is an integer, the result will be an unsigned integer.
1. Addition (+
)
Example: Both operands are integers.
gbase> SELECT 3+5 FROM dual;
+-----+
| 3+5 |
+-----+
| 8 |
+-----+
1 row in set
2. Subtraction (-
)
Example: Both operands are integers.
gbase> SELECT 3-5 FROM dual;
+-----+
| 3-5 |
+-----+
| -2 |
+-----+
1 row in set
3. Unary Minus
Description: Changes the sign of the parameter.
Example: The operand is an integer.
gbase> SELECT - 2 FROM dual;
+-----+
| - 2 |
+-----+
| -2 |
+-----+
1 row in set
Note: If the operand is of BIGINT
type, the return value will also be of BIGINT
type.
4. Multiplication (*
)
Example: Both operands are integers.
gbase> SELECT 3*5 FROM dual;
+-----+
| 3*5 |
+-----+
| 15 |
+-----+
1 row in set
5. Division (/
)
Example 1: Both operands are integers.
gbase> SELECT 3/5 FROM dual;
+--------+
| 3/5 |
+--------+
| 0.6000 |
+--------+
1 row in set
Example 2: The divisor is 0, the return value is NULL
.
gbase> SELECT 102/(1-1) FROM dual;
+-----------+
| 102/(1-1) |
+-----------+
| NULL |
+-----------+
1 row in set
Note: Division will only be performed with BIGINT
arithmetic if the result is being converted to an integer in the context.
6. Integer Division (DIV
)
Example: Both operands are integers.
gbase> SELECT 5 DIV 2 FROM dual;
+---------+
| 5 DIV 2 |
+---------+
| 2 |
+---------+
1 row in set
That concludes today's content. Thank you for reading!