LEAST

Returns the smallest value in a list of expressions.

Behavior Type

Stable

Syntax

LEAST ( expression1, expression2, ... expression-n )

Parameters

expression1, expression2, and expression-n are the expressions to be evaluated.

Notes

Examples

This example returns 5 as the least:

=> SELECT LEAST(7, 5, 9);
 LEAST
-------
     5
(1 row)

Putting quotes around the integer expressions returns the same result as the first example:

=> SELECT LEAST('7', '5', '9');
 LEAST
-------
 5
(1 row)

In the above example, the values are being compared as strings, so '10' would be less than '2'.

The next example returns 1.5, as INTEGER 2 is implicitly cast to FLOAT:

=> SELECT LEAST(2, 1.5);
 LEAST
-------
   1.5
(1 row)

The following example returns 'analytic' as the least:

=> SELECT LEAST('vertica', 'analytic', 'database');
  LEAST
----------
 analytic
(1 row)

Notice this next command returns NULL:

=> SELECT LEAST('vertica', 'analytic', 'database', null);
 LEAST
-------

(1 row)

And one more:

=> SELECT LEAST('sit', 'site', 'sight');
 LEAST
-------
 sight
(1 row)

See Also