Function Reference

LEAST

Returns the smallest of the given values.

PostgreSQL 17.5
LEAST(value[, ...])

Parameters

value
Value to compare: number, string or date

Return value

The smallest value; NULLs are skipped, NULL only if all arguments are NULL

Examples

Smallest of three numbers

PostgreSQL 17.5
SELECT LEAST(1, 2, -1);
least
-1

Smallest of three strings

PostgreSQL 17.5
SELECT LEAST('apple', 'banana', 'cherry');
least
apple

Comparison with NULL

PostgreSQL 17.5
SELECT LEAST(1, NULL, 3);
least
1

Details

Unlike the aggregate MIN, LEAST compares values within one row. In MySQL a NULL argument makes the whole result NULL, while here such arguments are simply skipped.

See also