Arithmetic operators

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 typeOperatorRight typeReturn type
timestamp+intervaltimestamp
interval+timestamptimestamp
interval+intervalinterval
timestamp-intervaltimestamp
timestamp-timestampinterval

List of arithmetic operators

OperatorAritySyntaxDescription
-unary-aNegates the input numeric expression.
+binarya + bAdds two numeric expressions (a and b).
-binarya - bSubtracts one numeric expression (b) from another (a).
*binarya * bMultiplies two numeric expressions (a and b).
/binarya / bDivides a by b, returning float. Nonzero values divided by zero produce a signed infinity; 0 / 0 produces NaN.
%binarya % bComputes 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.