Skip to main content

Mathematical Operators

Mathematical operators perform arithmetic operations on numeric values. CeloSQL supports standard mathematical operations for numeric data types.

Supported Operators

Operator

Description

Example

+

Addition

a + b

-

Subtraction

a - b

-

Unary minus (negation)

-a

*

Multiplication

a * b

/

Division

a / b

%

Modulo (remainder)

a % b

Operator Precedence

  1. - Unary minus (highest precedence)

  2. *, /, % Multiplication, division, modulo

  3. +, - Addition, subtraction (lowest precedence)

Use parentheses to override default precedence when needed.

Returns

Division Operator (/)

  • Always returns a DOUBLE type result.

Other Operators (+, -, *, %)

  • Mixed types are promoted to the more precise type

  • Returns NULL if any operand is NULL.

Limits

  • Division by zero returns inf (positive infinity) for positive dividends, -inf for negative dividends, and NaN for 0/0.

  • Integer overflow will result in an error.

  • Division always returns DOUBLE type, not integer division.

Examples

Basic Arithmetic

-- Example 1: Addition
> SELECT 1 + 1;
2

-- Example 2: Subtraction
> SELECT 1 - 1;
0

-- Example 3: Multiplication
> SELECT 1 * 2;
2

-- Example 4: Division (returns DOUBLE)
> SELECT 1 / 2;
0.5

-- Example 5: Division by zero returns infinity
> SELECT 5 / 0;
inf

> SELECT -5 / 0;
-inf

-- Example 6: Zero divided by zero returns NaN
> SELECT 0 / 0;
NaN

Unary Minus

-- Example 6: Negation
> SELECT -10;
-10

Decimal Arithmetic

-- Example 7: Division with decimals
> SELECT CAST(10 AS DECIMAL(10,2)) / CAST(3 AS DECIMAL(10,2));
3.33

-- Example 8: Precise decimal operations
> SELECT CAST(0.1 AS DECIMAL(10,2)) + CAST(0.2 AS DECIMAL(10,2));
0.30

NULL Handling

-- Example 15: NULL in arithmetic returns NULL
> SELECT 10 + NULL;
NULL

> SELECT NULL * 5;
NULL

See Also