GREATEST
Returns the largest value in a list of expressions.
Behavior Type
Syntax
GREATEST ( expression1, expression2, ... expression-n )
Parameters
expression1, expression2, and expression-n are the expressions to be evaluated.
Notes
- Works for all data types, and implicitly casts similar types. See Examples.
- A NULL value in any one of the expressions returns NULL.
- Depends on the collation setting of the locale.
Examples
This example returns 9 as the greatest in the list of expressions:
=> SELECT GREATEST(7, 5, 9); GREATEST ---------- 9 (1 row)
Note that putting quotes around the integer expressions returns the same result as the first example:
=> SELECT GREATEST('7', '5', '9'); GREATEST ---------- 9 (1 row)
The next example returns FLOAT 1.5 as the greatest because the integer is implicitly cast to float:
=> SELECT GREATEST(1, 1.5); GREATEST ---------- 1.5 (1 row)
The following example returns 'vertica' as the greatest:
=> SELECT GREATEST('vertica', 'analytic', 'database'); GREATEST ---------- vertica (1 row)
Notice this next command returns NULL:
=> SELECT GREATEST('vertica', 'analytic', 'database', null); GREATEST ---------- (1 row)
And one more:
=> SELECT GREATEST('sit', 'site', 'sight'); GREATEST ---------- site (1 row)