pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Rod Taylor <pg@rbt.ca>
Cc: Amos Hayes <ahayes@polkaroo.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: Find min and max values across two columns?
Date: Fri, 24 Mar 2006 16:20:31 -0500
Message-ID: <10495.1143235231@sss.pgh.pa.us> (raw)
In-Reply-To: <1143233215.90799.91.camel@home>
References: <DAD4674C-1896-4F24-B43B-B884491DB931@polkaroo.net>
	<1143233215.90799.91.camel@home>

Rod Taylor <pg@rbt.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



view thread (11+ messages)  latest in thread

Message-ID: <10495.1143235231@sss.pgh.pa.us>
Permalink:  ../10495.1143235231@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/10495.1143235231@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pg@rbt.ca, ahayes@polkaroo.net
  Subject: Re: Find min and max values across two columns?
  In-Reply-To: <10495.1143235231@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox