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
-- Function call
f1 := SUBTRACT(10, 3)
;Result
| f1 BIGINT |
|---|
| 7 |
.SUBTRACT(...) — chained
FeatureQL
SELECT
-- Integer literal: use parentheses for `.SUBTRACT` on a BIGINT value
f1 := (10).SUBTRACT(3),
-- Decimal base: chain without extra parentheses
f2 := 10.0.SUBTRACT(3)
;Result
| f1 BIGINT | f2 DECIMAL |
|---|---|
| 7 | 7.0 |
Date and time
FeatureQL
SELECT
-- Chained subtract on a timestamp
f1 := TIMESTAMP '2021-01-02'.SUBTRACT(INTERVAL '1 DAY')
;Result
| f1 TIMESTAMP |
|---|
| 2021-01-01T00:00:00 |
Edge cases
FeatureQL
SELECT
-- Interval between two timestamps via chained call
f1 := TIMESTAMP '2021-01-02'.SUBTRACT(TIMESTAMP '2021-01-01')
;Result
| f1 VARCHAR |
|---|
| 1 days |