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
    f1 := LEAST(1, 5, 3), -- Numeric minimum
    f2 := LEAST(1, 1, 1), -- All same values
    f3 := LEAST(-5, -1, -10), -- Negative numbers
    f4 := LEAST(NULL::BIGINT, 5, 3) -- NULL input
;
Result
f1 BIGINTf2 BIGINTf3 BIGINTf4 BIGINT
11-10NULL

Other types

FeatureQL
SELECT
    f1 := LEAST('apple', 'banana', 'cherry'), -- String minimum
    f2 := LEAST('a', 'A'), -- Case sensitive (A < a)
    f3 := LEAST(1.5, 2.3, 1.1) -- Decimal numbers
;
Result
f1 VARCHARf2 VARCHARf3 VARCHAR
appleA1.1

Arrays and rows

FeatureQL
SELECT
    f1 := LEAST(ARRAY(1, 2), ARRAY(1, 0)) -- Lexicographic min of two arrays
;
Result
f1 ARRAY
[1, 0]

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