Re: BUG #1188: evaluation order of select seems to be wrong

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, Holger Jakobs <holger(at)jakobs(dot)com>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #1188: evaluation order of select seems to be wrong
Date: 2004-07-10 02:27:42
Message-ID: 1823.1089426462@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com> writes:
> On Wed, 7 Jul 2004, Peter Eisentraut wrote:
>> Am Mittwoch, 7. Juli 2004 14:58 schrieb PostgreSQL Bugs List:
> Description: evaluation order of select seems to be wrong
>>
>> Please read this:
>> http://www.postgresql.org/docs/7.4/static/sql-expressions.html#SYNTAX-EXPRESS-EVAL

> The issue is that from what he said the standard may mandate that HAVING
> is applied before the select list is evaluated because it's part of the
> table expression.

I think this is indubitably a bug. We get it right in the non-aggregate
case, e.g.
select teamnr,win/lose from games where lose>0;
does not result in any divide-by-0 error.

I think (but haven't tested) that the fix just involves altering the
order of operations in nodeAgg.c so that we don't ExecProject until we
have checked the qual condition.

What surprises me is that no one has complained of this before. The
error exists at least back to 7.0, possibly forever...

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2004-07-10 03:02:15 Re: Improper processing of random values in sub-queries
Previous Message Tom Lane 2004-07-10 01:13:06 Re: BUG #1187: Problem in SQL Functions on Composite Types