Arithmetic operators¶
Arithmetic operators are functions that can be used as infix operators, or as prefix operators.
Syntax¶
arithmetic_expr ::=
| value_expr binary_operator value_expr
| unary_operator value_expr
arithmetic_infix_operator ::=
+ | - | * | / | %
arithmetic_unary_operator ::=
+ | -
Arguments¶
Parameter |
Description |
---|---|
|
Numeric expression, or expression that can be cast to a numeric expression |
Arithmetic operators¶
Operator |
Syntax |
Description |
---|---|---|
|
|
Converts a string to a numeric value. Identical to |
|
|
Adds two expressions together |
|
|
Negates a numeric expression |
|
|
Subtracts |
|
|
Multiplies |
|
|
Divides |
|
|
Modulu of |
Notes¶
If any of the inputs value are NULL, the result is NULL.
Examples¶
Coercing with a unary +
¶
numbers=> SELECT +'5';
5.00
Using infix operators¶
numbers=> SELECT 5*3 AS "5*3", 5+3 AS "5+3", 2-5 AS "2-5"
. , 2.0-5 AS "2.0-5", 11 % 5 AS "11%5", 11/5 AS "11/5", 11.0 / 5 AS "11.0/5";
5*3 | 5+3 | 2-5 | 2.0-5 | 11%5 | 11/5 | 11.0/5
----+-----+-----+-------+------+------+-------
15 | 8 | -3 | -3 | 1 | 2 | 2.2