Re: SELECT MAX returns wrong value

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Gavin Baumanis <gavinb(at)eclinic(dot)com(dot)au>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: SELECT MAX returns wrong value
Date: 2007-12-13 23:32:38
Message-ID: 22441.1197588758@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Gavin Baumanis <gavinb(at)eclinic(dot)com(dot)au> 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Gary Stainburn 2007-12-14 17:02:52 odd error updating - varchar
Previous Message Gavin Baumanis 2007-12-13 23:09:27 SELECT MAX returns wrong value