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 | |
| Subtraction | |
| Unary minus (negation) | |
| Multiplication | |
| Division | |
| Modulo (remainder) | |
Operator Precedence
-Unary minus (highest precedence)*,/,%Multiplication, division, modulo+,-Addition, subtraction (lowest precedence)
Use parentheses to override default precedence when needed.
Returns
Division Operator (/)
Always returns a
DOUBLEtype result.
Other Operators (+, -, *, %)
Mixed types are promoted to the more precise type
Returns
NULLif any operand isNULL.
Limits
Division by zero returns
inf(positive infinity) for positive dividends,-inffor negative dividends, andNaNfor0/0.Integer overflow will result in an error.
Division always returns
DOUBLEtype, 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