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(value: T, low: T, high: T) → T sql
| Parameter | Type | Required | Description |
|---|---|---|---|
value | T | Yes | Value to constrain |
low | T | Yes | Lower bound (inclusive) |
high | T | Yes | Upper bound (inclusive) |
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
RETURN
-- Above high → high
f1 := CLAMP(15, 0, 10),
-- Inside range
f2 := CLAMP(5, 0, 10),
-- Below low → low
f3 := CLAMP(-3, 0, 10),
-- Decimal bounds
f4 := CLAMP(3.0::DECIMAL(3,1), 1.0::DECIMAL(3,1), 5.0::DECIMAL(3,1))
;Result
| f1 BIGINT | f2 BIGINT | f3 BIGINT | f4 DECIMAL |
|---|---|---|---|
| 10 | 5 | 0 | 3.0 |
On this page