SUBTRACT()
All functions > MATH > SUBTRACT()
Returns the result of subtracting the second value from the first.
Signatures
Numeric subtraction
Returns: Result of the subtraction
SUBTRACT(number1: T, number2: T) → T sql
| Parameter | Type | Required | Description |
|---|---|---|---|
number1 | T | Yes | Number to subtract from |
number2 | T | Yes | Number to subtract |
With:
T: Any numeric type
Signature notes:
- Both arguments must be of the same numeric type
- Returns NULL if either operand is NULL
- Order matters:
SUBTRACT(a, b) ≠ SUBTRACT(b, a)
Related operators
Examples
SUBTRACT(...)
FeatureQL
SELECT
f1 := SUBTRACT(10, 3) -- Function call
;Result
| f1 BIGINT |
|---|
| 7 |
.SUBTRACT(...) — chained
FeatureQL
SELECT
f1 := (10).SUBTRACT(3), -- Integer literal: use parentheses for `.SUBTRACT` on a BIGINT value
f2 := 10.0.SUBTRACT(3) -- Decimal base: chain without extra parentheses
;Result
| f1 BIGINT | f2 VARCHAR |
|---|---|
| 7 | 7.0 |
Date and time
FeatureQL
SELECT
f1 := TIMESTAMP '2021-01-02'.SUBTRACT(INTERVAL '1 DAY'), -- Chained subtract on a timestamp
f2 := TIMESTAMP '2021-01-02'.SUBTRACT(TIMESTAMP '2021-01-01') -- Interval between two timestamps via chained call
;Result
| f1 TIMESTAMP | f2 VARCHAR |
|---|---|
| 2021-01-01T00:00:00 | 1 days |
Edge cases
FeatureQL
SELECT
f1 := SUBTRACT(5, 5), -- Equal operands
f2 := SUBTRACT(1, 7), -- Negative result
f3 := SUBTRACT(0, -5) -- Subtracting a negative
;Result
| f1 BIGINT | f2 BIGINT | f3 BIGINT |
|---|---|---|
| 0 | -6 | 5 |