Skip site navigation (1) Skip section navigation (2)

Re: BUG #1528: Rows returned that should be excluded by WHERE clause

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Gill, Jerry T(dot)" <JTGill(at)west(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #1528: Rows returned that should be excluded by WHERE clause
Date: 2005-03-08 17:14:35
Message-ID: 8272.1110302075@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-bugs
"Gill, Jerry T." <JTGill(at)west(dot)com> writes:
> Just an interesting side note here, this behavior is identical to DB2. I am not sure if that makes it correct or not, but here is an example.
> [gill(at)c2n2 gill]$ db2 "select 2 as id, max(apn3) from phoenix.client where 2 =1"

> ID          2
> ----------- ------
>           2      -

>   1 record(s) selected.

In the WHERE case I think there's no question that the above is correct:
WHERE is defined to filter rows before application of aggregates, so
zero rows arrive at the MAX aggregate, and that means it produces a
NULL.

But HAVING is supposed to filter after aggregation, so I think probably
there should be no row out in that case.

What does DB2 do when you say HAVING 2 = 1?

			regards, tom lane

In response to

pgsql-bugs by date

Next:From: Gill, Jerry T.Date: 2005-03-08 17:31:03
Subject: Re: BUG #1528: Rows returned that should be excluded by WHERE clause
Previous:From: Gill, Jerry T.Date: 2005-03-08 16:41:53
Subject: Re: BUG #1528: Rows returned that should be excluded by WHERE clause

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group