CLAMP()
All functions > MATH > CLAMP()
Constrains a value to a closed interval: the result is the value limited to lie between low and high (inclusive).
Signatures
Numeric and comparable scalars
Returns: value saturated into [low, high]
CLAMP(low: T, high: T, value: T) → T sql
| Parameter | Type | Required | Description |
|---|---|---|---|
low | T | Yes | Lower bound (inclusive) |
high | T | Yes | Upper bound (inclusive) |
value | T | Yes | Value to constrain |
With:
T: Any numeric type
Signature notes:
- Equivalent to applying a lower bound then an upper bound: neither bound is swapped for you; if low > high, semantics follow GREATEST/LEAST on the backend
- All three arguments must share one compatible type
- Returns NULL if any argument is NULL
Examples
FeatureQL
SELECT
f1 := CLAMP(0, 10, 15), -- Above high → high
f2 := CLAMP(0, 10, 5), -- Inside range
f3 := CLAMP(0, 10, -3), -- Below low → low
f4 := CLAMP(1.0::DECIMAL(3,1), 5.0::DECIMAL(3,1), 3.0::DECIMAL(3,1)) -- Decimal bounds
;Result
| f1 BIGINT | f2 BIGINT | f3 BIGINT | f4 VARCHAR |
|---|---|---|---|
| 10 | 5 | 0 | 3.0 |
On this page