Re: Find min and max values across two columns?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Rod Taylor <pg(at)rbt(dot)ca>
Cc: Amos Hayes <ahayes(at)polkaroo(dot)net>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Find min and max values across two columns?
Date: 2006-03-24 21:20:31
Message-ID: 10495.1143235231@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Rod Taylor <pg(at)rbt(dot)ca> writes:
> The reason for the subselect is to prevent multiple calculations of
> individual column aggregates. I believe it *may* be calculated multiple
> times otherwise this would work just as well:

> select case when max(a) > max(b) then max(a) else max(b) end as max from
> tab;

Just for the record, we've gotten that right since 7.4. greatest()
would be a notationally cleaner solution than CASE, but multiple
occurrences of identical aggregates don't cost much of anything.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Amos Hayes 2006-03-24 21:34:43 Re: Find min and max values across two columns?
Previous Message Rod Taylor 2006-03-24 21:20:06 Re: Find min and max values across two columns?