how to combine multiple timestamps and keep the most recent one? I have a table with many timestamps in it, some of which may be null.  Is there a way to combine them all and keep the most recent timestamp so I don't have to reference each timestamp individually?

For example, given this over-simplified example:

SELECT blah
FROM foo
WHERE
    ts1 &gt;= '2018-04-17' OR
    ts2 &gt;= '2018-04-17' OR
    ts3 &gt;= '2018-04-17';


I suspect there must be a way to turn it into something like this:

SELECT blah, somefunc(ts1, ts2, ts3) AS ts
FROM foo
WHERE ts &gt;= '2018-04-17';
You need the greatest() function:

SELECT greatest(now(), 
                now() + interval '1 minute', 
                CURRENT_DATE::timestamptz, 
                NULL);

           greatest            
───────────────────────────────
 2018-04-17 19:40:04.568827+02


About NULLs:


  NULL values in the list are ignored. The result will be NULL only if all the expressions evaluate to NULL.


Please note that comparing timestamps (especially timestamps with time zones) to simple date values sometimes result in surprises.  I always try to use something like date_trunc('day', '2018-01-05'::date) to get a type that can be compared cleanly.