The greatest() function returns the largest of the input values.
You must specify two input values; you can specify up to a maximum of four values (variable length lists are not supported). The comparison for string values is based on a character set value. The character with the higher character set value is considered the greatest value.
int4 = Greatest(int4 value1, int4 value2, ...);
int8 = Greatest(int8 value1, int8 value2, ...);
double = Greatest(double value1, double value2, ...);
date = Greatest(date value1, date value2, ...);
varchar = Greatest(varchar value1, varchar value2, ...);
timestamp = Greatest(timestamp value1, timestamp value2, ...);
time = Greatest(time value1, time value2, ...);
timetz = Greatest(timetz value1, timetz value2, ...);
interval = Greatest(interval value1, interval value2, ...);
The value1 value specifies the first input to compare.
The value2 value specifies the second input to compare.
The value3 value specifies the third input to compare.
The value4 value specifies the fourth input to compare.
select greatest(12,45,85);
greatest
----------
85
(1 row)
select greatest(to_date('26-01-1234','DD-MM-YYYY'),
to_date('27 Feb 1200','DD Mon YYYY'));
GREATEST
------------
1234-01-26
(1 row)
select greatest('Alpha Beta gamma','a');
GREATEST
----------
a
(1 row)
select greatest(timestamp('25-10-1756 09:00:30'),
timestamp('24-11-1755 08:45:00'));
GREATEST
---------------------
1756-10-25 09:00:30
(1 row)