Shape / columns · All operations

Add, subtract, multiply or divide

A variant of Apply a maths function

Combine numbers with arithmetic operators such as plus, minus, times, divide and remainder.

Status

In arcform

Runs as a SQL step

arcform carries it as a sql: step today.

The DuckDB step

Add, subtract, multiply, divide and take the remainder

SQL
CREATE TEMP TABLE pairs AS SELECT * FROM (VALUES (1, 17, 5), (2, -17, 5), (3, 0, 5)) t(id, a, b);
CREATE TEMP TABLE result AS
SELECT id, a + b AS plus, a - b AS minus, a * b AS times, a / b AS divided, a // b AS whole, a % b AS remainder FROM pairs;
SELECT * FROM result ORDER BY id;
SELECT CASE WHEN ((SELECT [plus, minus, times, whole, remainder] FROM result WHERE id = 1) = [22, 12, 85, 3, 2] AND (SELECT divided FROM result WHERE id = 1) = 3.4 AND (SELECT [plus, minus, times, whole, remainder] FROM result WHERE id = 2) = [-12, -22, -85, -3, -2] AND (SELECT divided FROM result WHERE id = 2) = -3.4 AND (SELECT [plus, minus, times, whole, remainder] FROM result WHERE id = 3) = [5, -5, 0, 0, 0]) THEN 'as expected' ELSE error('the plus, minus, times, divide, whole-number divide and remainder of 17 and 5, and of -17 and 5, were not as expected') END AS verdict;
  • The statement builds its own data.
  • It needs nothing installed beyond DuckDB itself.
  • The statement checks its own result and raises an error when it is wrong: “the plus, minus, times, divide, whole-number divide and remainder of 17 and 5, and of -17 and 5, were not as expected”.
  • It passed on DuckDB v2.0.0 (Cyanoptera) d54cbbe3df.

What other tools call it

Meridian's classification; an independent blind rating agreed on 95.7% of 324 rows (variant, version 3).

Apache DataFusion (1)
Apache NiFi (2)
Azure Data Factory (1)
  • Math functionsread 2026-09-27

    9 functions: add, div, max, min, mod, …

Duckle (1)
Ibis (7)
  • Addread 2026-09-27

    Add two values

  • Divideread 2026-09-27

    Divide the left value by the right

  • FloorDivideread 2026-09-27

    Divide the left value by the right and round down to an integer

  • Modulusread 2026-09-27

    Remainder of dividing the left value by the right

  • Multiplyread 2026-09-27

    Multiply two values

  • Negateread 2026-09-27

    Flip the sign of a value

  • Subtractread 2026-09-27

    Subtract the right value from the left

Polars (1)
Trifacta (1)
  • Numeric Operatorsread 2026-09-27

    Add, subtract, multiply, divide operators computing a value from two operands

Background

Arithmetic is an elementary branch of mathematics that deals with numerical operations like addition, subtraction, multiplication and division.[1] Modulo is the binary operation whose value is the remainder or signed remainder of a division of one number by another.[2] In DuckDB, / performs floating-point division even between integers, so 5 / 2 is 2.5, while // performs integer division, so 5 // 2 is 2.[3]

When to use it

In PostgreSQL, division of integral types truncates the result towards zero, so 5 / 2 is 2 and (-5) / 2 is -2.[4] Check every division between two integer columns when moving a query between DuckDB and PostgreSQL. (Meridian's view) In DuckDB, the add, subtract and multiply functions are aliases for +, - and *, but divide(x, y) is an alias for x // y, not for x / y.[3]

When exactly one of the two numbers is negative, programming languages differ in how they define the result of a modulo operation.[2] A test for an odd number written as n % 2 = 1 fails for negative odd numbers wherever the remainder takes the sign of the dividend, because n % 2 then returns -1.[2]

DuckDB recommends the DECIMAL type, or its NUMERIC alias, for numbers with a known number of decimal digits that need exact additions, subtractions and multiplications, such as monetary amounts.[5] In DuckDB, multiplication, addition and subtraction of fixed-point decimals are exact, while the same operations on floating-point binary types are only approximate.[5]

The method

In nearly all computing systems, the quotient q and remainder r of a divided by a non-zero n satisfy a = nq + r, with the absolute value of r less than that of n.[2] The condition a = nq + r still leaves the sign of a non-zero remainder open, and programming languages choose it depending on the language and the signs of the operands.[2] With truncated division the quotient is rounded towards zero, so the remainder has the same sign as the dividend.[2] Donald Knuth promotes floored division, whose quotient is rounded down, so the remainder has the same sign as the divisor.[2] The SQL:1999 mod(x,y) function and the SQL:2011 % operator follow the truncated definition.[2] DuckDB's fdiv and fmod use the floored definition and always return a DOUBLE value.[3]

In PostgreSQL, a call mixing argument types, such as integer + numeric, is resolved by using the type that comes later in the list smallint, integer, bigint, numeric, real and double precision.[4] In DuckDB, adding, subtracting or multiplying two fixed-point decimals returns a decimal wide enough to hold the exact result, or throws an error if the width needed would exceed 38.[5] DuckDB uses approximate floating-point arithmetic for all divisions that involve fixed-point decimals, and accordingly returns floating-point data types.[5]

Compared with the alternatives

DuckDB's decimal_division function, added in DuckDB 2.0, divides a DECIMAL value using exact decimal arithmetic with round-half-to-even and returns a DECIMAL rather than a DOUBLE.[3] Use decimal_division where a quotient must stay exact to a fixed number of places, and the / operator where a floating-point answer is good enough. (Meridian's view)