Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 44C9A2E42A2 for ; Mon, 7 Jan 2008 18:39:34 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 96676-01 for ; Mon, 7 Jan 2008 18:39:22 -0400 (AST) Received: from mx1.ntghosting.com (mx1.ntghosting.com [74.202.50.131]) by postgresql.org (Postfix) with ESMTP id F35322E424C for ; Mon, 7 Jan 2008 18:39:02 -0400 (AST) Received: from godzilla.local.scalefeather.com ([65.24.34.39]) by mx1.ntghosting.com (SpamEdge v0.7.10.22) with ASMTP (SSL) id NXU00000; Mon, 07 Jan 2008 17:39:00 -0500 Subject: Re: Get the max(value1, value2, value3) from a table From: Josh Williams To: emilu@encs.concordia.ca Cc: pgsql-sql@postgresql.org In-Reply-To: <4782A1B2.5050804@encs.concordia.ca> References: <4782A1B2.5050804@encs.concordia.ca> Content-Type: text/plain Date: Mon, 07 Jan 2008 17:38:57 -0500 Message-Id: <1199745537.5877.9.camel@godzilla.local.scalefeather.com> Mime-Version: 1.0 X-Mailer: Evolution 2.6.3 Content-Transfer-Encoding: 7bit X-Spam-Rcpt: emilu@encs.concordia.ca X-Spam-Org: X-Nexus-Flag: 10 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200801/38 X-Sequence-Number: 29891 On Mon, 2008-01-07 at 17:03 -0500, Emi Lu wrote: > select ?max?(col1, col2, col3) as result; > will return > > result > ------- > 5 > 8 > 12 > > (3 rows) 8.1 (I believe?) introduced GREATEST(), which does precisely what you're looking for. But if 8.0 is a must, you'll probably have to create your own function to do that. Which should be fairly easy to do if you're working with a static number of columns/data types/etc... - Josh