Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id B087B2E38E7 for ; Thu, 13 Dec 2007 19:32:47 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 71109-01-2 for ; Thu, 13 Dec 2007 19:32:40 -0400 (AST) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 37D172E393D for ; Thu, 13 Dec 2007 19:32:44 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id lBDNWcc5022442; Thu, 13 Dec 2007 18:32:38 -0500 (EST) To: Gavin Baumanis cc: pgsql-sql@postgresql.org Subject: Re: SELECT MAX returns wrong value In-reply-to: <4761BBA7.7030800@eclinic.com.au> References: <4761BBA7.7030800@eclinic.com.au> Comments: In-reply-to Gavin Baumanis message dated "Fri, 14 Dec 2007 10:09:27 +1100" Date: Thu, 13 Dec 2007 18:32:38 -0500 Message-ID: <22441.1197588758@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/84 X-Sequence-Number: 29776 Gavin Baumanis writes: > If I perform the following SQL > SELECT MAX(column) FROM table WHERE expression > and there is no match, Postgres returns a record count of 1. > There is no value in max, it is NULL. This is the behavior required by the SQL standard. > Thus trying to perform some "other" tasks based on if a record was > returned or not is proving a little difficult in this instance. Test for null result, perhaps? regards, tom lane