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
ParameterTypeRequiredDescription
lowTYesLower bound (inclusive)
highTYesUpper bound (inclusive)
valueTYesValue 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 BIGINTf2 BIGINTf3 BIGINTf4 VARCHAR
10503.0

Last update at: 2026/05/26 17:22:09