X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A65DA9DCDDF for ; Fri, 24 Mar 2006 17:22:28 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 51343-10-5 for ; Fri, 24 Mar 2006 17:22:29 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from jandor.look.ca (theta1.look.ca [207.136.80.122]) by postgresql.org (Postfix) with ESMTP id A6CDB9DCE0B for ; Fri, 24 Mar 2006 17:22:26 -0400 (AST) Received: from 209-161-222-80.dsl.look.ca ([209.161.222.80]) by jandor.look.ca with esmtp (Exim 4.20) id 1FMtjl-0003zi-Fo; Fri, 24 Mar 2006 21:22:25 +0000 From: Rod Taylor To: Tom Lane Cc: Amos Hayes , pgsql-sql@postgresql.org In-Reply-To: <10495.1143235231@sss.pgh.pa.us> References: <1143233215.90799.91.camel@home> <10495.1143235231@sss.pgh.pa.us> Date: Fri, 24 Mar 2006 16:20:06 -0500 Message-Id: <1143235206.90799.108.camel@home> Mime-Version: 1.0 X-Mailer: Evolution 2.4.2.1 FreeBSD GNOME Team Port X-SA-Exim-Mail-From: pg@rbt.ca Subject: Re: Find min and max values across two columns? Content-Type: text/plain Content-Transfer-Encoding: 7bit X-SA-Exim-Version: 3.1 (built Tue Feb 24 05:09:27 GMT 2004) X-SA-Exim-Scanned: Yes X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.094 required=5 tests=[AWL=0.094] X-Spam-Score: 0.094 X-Spam-Level: X-Archive-Number: 200603/396 X-Sequence-Number: 24742 On Fri, 2006-03-24 at 16:20 -0500, Tom Lane wrote: > Rod Taylor 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. Thanks. I could not remember one way or the other. --