X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 2D6699FA2EB for ; Mon, 15 May 2006 18:42:30 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 81610-04-2 for ; Mon, 15 May 2006 18:42:24 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 22B249FA92E for ; Mon, 15 May 2006 18:42:20 -0300 (ADT) Received: from perseverance.encs.concordia.ca (perseverance-96.encs.concordia.ca [132.205.96.94]) by svr4.postgresql.org (Postfix) with ESMTP id D4C935B6BDB for ; Mon, 15 May 2006 21:40:49 +0000 (GMT) Received: from [132.205.47.225] (emilu@cacao.encs.concordia.ca [132.205.47.225]) by perseverance.encs.concordia.ca (8.13.6/8.13.6) with ESMTP id k4FLeeAY028925; Mon, 15 May 2006 17:40:40 -0400 Message-ID: <4468F558.7070407@encs.concordia.ca> Date: Mon, 15 May 2006 17:40:40 -0400 From: Emi Lu Reply-To: emilu@encs.concordia.ca User-Agent: Mozilla Thunderbird 1.0.7 (X11/20050923) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: Amos Hayes , pgsql-sql@postgresql.org Subject: Re: Find min and max values across two columns? References: <9558.1143234035@sss.pgh.pa.us> In-Reply-To: <9558.1143234035@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.43 on perseverance.encs.concordia.ca at 2006/05/15 17:40:40 EDT X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/109 X-Sequence-Number: 25140 Hello, I tried "select greatest(max(a), max(b)) from public.test", but I got the following errors: ERROR: function greatest(integer, integer) does not exist HINT: No function matches the given name and argument types. You may need to add explicit type casts. May I know where I can read the docs about greatest & least please. I am using PostgreSQL 8.0.7. Thanks, Ying >Amos Hayes writes: > > >>I'm trying to build a query that among other things, returns the >>minimum and maximum values contained in either of two columns. >> >> > >I think you might be looking for > > select greatest(max(columnA), max(columnB)) from tab; > select least(min(columnA), min(columnB)) from tab; > >greatest/least are relatively new but you can roll your own in >older PG releases. > > regards, tom lane > >---------------------------(end of broadcast)--------------------------- >TIP 9: In versions below 8.0, the planner will ignore your desire to > choose an index scan if your joining column's datatypes do not > match > >