LEAST(...)
All functions > COMPARISON > LEAST(...)
Returns the least (minimum) value from a list of arguments.
Syntax
LEAST(expr, expr, ...)
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
</> - Can accept any number of arguments (not just two)
- Equivalent to finding the minimum value across multiple columns
- Opposite of GREATEST function
Related Functions
Examples
Numeric values
FeatureQL
SELECT
-- Numeric minimum
f1 := LEAST(1, 5, 3),
-- All same values
f2 := LEAST(1, 1, 1),
-- Negative numbers
f3 := LEAST(-5, -1, -10),
-- NULL input
f4 := LEAST(NULL::BIGINT, 5, 3)
;Result
| f1 BIGINT | f2 BIGINT | f3 BIGINT | f4 BIGINT |
|---|---|---|---|
| 1 | 1 | -10 | NULL |
Other types
FeatureQL
SELECT
-- String minimum
f1 := LEAST('apple', 'banana', 'cherry'),
-- Case sensitive (A < a)
f2 := LEAST('a', 'A'),
-- Decimal numbers
f3 := LEAST(1.5, 2.3, 1.1)
;Result
| f1 VARCHAR | f2 VARCHAR | f3 VARCHAR |
|---|---|---|
| apple | A | 1.1 |
Arrays and rows
FeatureQL
SELECT
-- Lexicographic min of two arrays
f1 := LEAST(ARRAY(1, 2), ARRAY(1, 0))
;Result
| f1 ARRAY |
|---|
| [1, 0] |