BETWEEN
All functions > COMPARISON > BETWEEN
Returns TRUE if a value is within a specified range (inclusive)
Syntax
expr BETWEEN lower AND upper
Function form
Returns: TRUE if expr lies in the inclusive range, or NULL if any argument is NULL
BETWEEN(expr: T, lower: T, upper: T, [digits: BIGINT]) → BOOLEAN sql
| Parameter | Type | Required | Description |
|---|---|---|---|
expr | T | Yes | Value to test |
lower | T | Yes | Lower bound (inclusive) |
upper | T | Yes | Upper bound (inclusive) |
digits | BIGINT | No | Digits of rounded FLOAT/DOUBLE precision (.N); not applied when Inf or magnitude overflows DECIMAL(38, N) staging |
Notes
- All three values must be of comparable types
- The range is inclusive of both bounds
- Equivalent to: value >= lower_bound AND value <= upper_bound (same three-valued AND as comparison chains)
- A NULL (or nested-NULL composite) in the probe or a bound propagates through that conjunct; the other conjunct can still force FALSE
- For ARRAY and ROW, uses the same ordering/
=poisoning rules as</>= - On FLOAT/DOUBLE, write
.N(e.g.>.2,=.4,BETWEEN.3) for N decimal places of rounded precision viaDECIMAL(38, N)staging, not N significant digits. Omitting.Nuses 15 decimal places (DECIMAL(38, 15)) IN.Nis the same suffix on membership- Any NaN operand makes the comparison NULL
- Infinity, or any finite value too large for
DECIMAL(38, N), falls back to a raw float compare —.Nrounding is not applied on that path
Examples
BETWEEN — inclusive bounds
FeatureQL
RETURN
-- Inside range
f1 := 3 BETWEEN 1 AND 5,
-- Lower bound inclusive
f2 := 1 BETWEEN 1 AND 5,
-- Upper bound inclusive
f3 := 5 BETWEEN 1 AND 5,
-- Below range
f4 := 0 BETWEEN 1 AND 5
;Result
| f1 BOOLEAN | f2 BOOLEAN | f3 BOOLEAN | f4 BOOLEAN |
|---|---|---|---|
| true | true | true | false |
BETWEEN — arrays and rows
FeatureQL
RETURN
-- Value within lexicographic bounds
f1 := ARRAY(2, 3) BETWEEN ARRAY(1, 1) AND ARRAY(3, 3)
;Result
| f1 BOOLEAN |
|---|
| true |
BETWEEN — NULL propagation
FeatureQL
RETURN
-- NULL value
f1 := NULL::BIGINT BETWEEN 1 AND 10,
-- NULL bound
f2 := 3 BETWEEN NULL::BIGINT AND 10,
-- Bound poisoned; other conjunct FALSE → FALSE
f3 := ROW(9::BIGINT, 9::BIGINT)
BETWEEN ROW(0::BIGINT, NULL::BIGINT)
AND ROW(2::BIGINT, 2::BIGINT),
-- Probe poisons both conjuncts → NULL
f4 := ROW(9::BIGINT, NULL::BIGINT)
BETWEEN ROW(0::BIGINT, 0::BIGINT)
AND ROW(2::BIGINT, 2::BIGINT)
;Result
| f1 BOOLEAN | f2 BOOLEAN | f3 BOOLEAN | f4 BOOLEAN |
|---|---|---|---|
| NULL | NULL | false | NULL |
BETWEEN — functional call
FeatureQL
RETURN
-- `BETWEEN(expr, lower, upper)` matches keyword `BETWEEN … AND …`
f1 := BETWEEN(3, 1, 5),
-- Below the inclusive range
f2 := BETWEEN(0, 1, 5)
;Result
| f1 BOOLEAN | f2 BOOLEAN |
|---|---|
| true | false |
BETWEEN — chained
FeatureQL
RETURN
-- Receiver is the value; arguments are lower and upper bounds
f1 := (3).BETWEEN(1, 5),
-- Same semantics as the prefix call
f2 := (0).BETWEEN(1, 5)
;Result
| f1 BOOLEAN | f2 BOOLEAN |
|---|---|
| true | false |