GREATEST
Returns the largest of the given values.
PostgreSQL 17.5
GREATEST(value[, ...])Parameters
- value
- Value to compare: number, string or date
Return value
The largest value; NULLs are skipped, NULL only if all arguments are NULL
Examples
Largest of three numbers
PostgreSQL 17.5
SELECT GREATEST(1, 2, -1);Largest of three strings
PostgreSQL 17.5
SELECT GREATEST('apple', 'banana', 'cherry');Comparison with NULL
PostgreSQL 17.5
SELECT GREATEST(1, NULL, 3);Details
Unlike the aggregate MAX, GREATEST compares values within one row. In MySQL a NULL argument makes the whole result NULL, while here such arguments are simply skipped.