pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Scott Marlowe <scott.marlowe@gmail.com>
To: Gavin Baumanis <gavinb@eclinic.com.au>
Cc: pgsql-sql@postgresql.org
Subject: Re: SELECT MAX returns wrong value
Date: Fri, 14 Dec 2007 11:24:14 -0600
Message-ID: <dcc563d10712140924h758ec6dep8129f9ef71968df9@mail.gmail.com> (raw)
In-Reply-To: <4761BBA7.7030800@eclinic.com.au>
References: <4761BBA7.7030800@eclinic.com.au>

On Dec 13, 2007 5:09 PM, Gavin Baumanis <gavinb@eclinic.com.au> wrote:
> Hi Everyone,
>
> Sorry if I am missing something obvious but I think I have found a bug.
> 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.

that's because you got one record back.  A null one, but a record none the less.

The standard way of doing this is:

select count(column) from table where expression.

since null columns don't get counted, it will return zero if they're all null.



view thread (3+ messages)

Message-ID: <dcc563d10712140924h758ec6dep8129f9ef71968df9@mail.gmail.com>
Permalink:  ../dcc563d10712140924h758ec6dep8129f9ef71968df9@mail.gmail.com/
Also on:    postgresql.org/message-id/dcc563d10712140924h758ec6dep8129f9ef71968df9@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: scott.marlowe@gmail.com, gavinb@eclinic.com.au
  Subject: Re: SELECT MAX returns wrong value
  In-Reply-To: <dcc563d10712140924h758ec6dep8129f9ef71968df9@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox