Arithmetic operators
On this page
Arithmetic operators calculate values from numeric expressions. + and - also support timestamps and intervals.
Numeric inputs use int, uint, or float. The supported date and time operations are:
| Left type | Operator | Right type | Return type |
|---|---|---|---|
timestamp | + | interval | timestamp |
interval | + | timestamp | timestamp |
interval | + | interval | interval |
timestamp | - | interval | timestamp |
timestamp | - | timestamp | interval |
List of arithmetic operators
| Operator | Arity | Syntax | Description |
|---|---|---|---|
- | unary | -a | Negates the input numeric expression. |
+ | binary | a + b | Adds two numeric expressions (a and b). |
- | binary | a - b | Subtracts one numeric expression (b) from another (a). |
* | binary | a * b | Multiplies two numeric expressions (a and b). |
/ | binary | a / b | Divides a by b, returning float. Nonzero values divided by zero produce a signed infinity; 0 / 0 produces NaN. |
% | binary | a % b | Computes the modulo of numeric expression a by b. |
Examples
Calculate the completion rate and number of unfinished checkouts for each channel:
VALUES ('web', 80, 23), ('mobile', 60, 17)
SELECT $0 AS channel, $1 AS checkouts, $2 AS completed
SELECT
channel,
checkouts - completed AS unfinished,
round(completed / checkouts * 1000.0) / 10.0 AS completion_pct+---------+------------+----------------+
| channel | unfinished | completion_pct |
+---------+------------+----------------+
| web | 57 | 28.8 |
| mobile | 43 | 28.3 |
+---------+------------+----------------+Division returns float even when both counts are integers. The multiplication and rounding express the ratio as a percentage with one decimal place.