Introduction to Arithmetic Operators in GBase 8a MPP Cluster

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 with BIGINT (64-bit) precision, and the result is returned.
If one para…


This content originally appeared on DEV Community and was authored by Cong Li

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 with BIGINT (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!


This content originally appeared on DEV Community and was authored by Cong Li


Print Share Comment Cite Upload Translate Updates
APA

Cong Li | Sciencx (2024-09-04T03:08:13+00:00) Introduction to Arithmetic Operators in GBase 8a MPP Cluster. Retrieved from https://www.scien.cx/2024/09/04/introduction-to-arithmetic-operators-in-gbase-8a-mpp-cluster/

MLA
" » Introduction to Arithmetic Operators in GBase 8a MPP Cluster." Cong Li | Sciencx - Wednesday September 4, 2024, https://www.scien.cx/2024/09/04/introduction-to-arithmetic-operators-in-gbase-8a-mpp-cluster/
HARVARD
Cong Li | Sciencx Wednesday September 4, 2024 » Introduction to Arithmetic Operators in GBase 8a MPP Cluster., viewed ,<https://www.scien.cx/2024/09/04/introduction-to-arithmetic-operators-in-gbase-8a-mpp-cluster/>
VANCOUVER
Cong Li | Sciencx - » Introduction to Arithmetic Operators in GBase 8a MPP Cluster. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/04/introduction-to-arithmetic-operators-in-gbase-8a-mpp-cluster/
CHICAGO
" » Introduction to Arithmetic Operators in GBase 8a MPP Cluster." Cong Li | Sciencx - Accessed . https://www.scien.cx/2024/09/04/introduction-to-arithmetic-operators-in-gbase-8a-mpp-cluster/
IEEE
" » Introduction to Arithmetic Operators in GBase 8a MPP Cluster." Cong Li | Sciencx [Online]. Available: https://www.scien.cx/2024/09/04/introduction-to-arithmetic-operators-in-gbase-8a-mpp-cluster/. [Accessed: ]
rf:citation
» Introduction to Arithmetic Operators in GBase 8a MPP Cluster | Cong Li | Sciencx | https://www.scien.cx/2024/09/04/introduction-to-arithmetic-operators-in-gbase-8a-mpp-cluster/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.