LEAST(...)
All functions > COMPARISON > LEAST(...)
Returns the least (minimum) value from a list of arguments.
Signatures
Returns: Least of the arguments, or NULL if any argument is NULL
LEAST_FN(exprs: T, ...) → T sql
| Parameter | Type | Required | Description |
|---|---|---|---|
exprs | T, ... | Yes | Variadic arguments in SQL (at least one; all mutually compatible) |
Notes
- All arguments must be of the same or compatible types
- If any argument is NULL, the result is NULL
- For strings, uses lexicographic (dictionary) ordering
- For dates/timestamps, returns the earliest date/time
- For ARRAY and ROW, uses the same ordering as
</>(see Related operators for variadicLEAST(...)examples) - Can accept any number of arguments (not just two)
- Equivalent to finding the minimum value across multiple columns
- Opposite of GREATEST function
Related operators
Examples
LEAST_FN — single-array encoding
FeatureQL
SELECT
f1 := LEAST_FN(ARRAY[1, 5, 3]), -- Same semantics as variadic `LEAST`
f2 := LEAST_FN(ARRAY['a', 'z', 'm']) -- Lexicographic min via array encoding
;Result
| f1 BIGINT | f2 VARCHAR |
|---|---|
| 1 | a |
LEAST_FN — NULL propagation
FeatureQL
SELECT
f1 := LEAST_FN(ARRAY[NULL::BIGINT, 3]), -- Any NULL in the list → NULL result
f2 := LEAST_FN(ARRAY[1, NULL::BIGINT, 3]) -- NULL anywhere → NULL result
;Result
| f1 BIGINT | f2 BIGINT |
|---|---|
| NULL | NULL |
LEAST_FN — arrays of arrays
FeatureQL
SELECT
f1 := LEAST_FN(ARRAY[ARRAY(1, 2), ARRAY(1, 0)]) -- Lexicographic min of two array values
;Result
| f1 ARRAY |
|---|
| [1, 0] |