Re: Query returning incorrect results

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michael Fork <mfork(at)toledolink(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Query returning incorrect results
Date: 2000-10-09 02:41:15
Message-ID: 21279.971059275@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Michael Fork <mfork(at)toledolink(dot)com> writes:
> When I execute the following two queries, the results differ -- with the
> only change being that another table is joined (a 1-1 join that should not
> affect the results -- I reduced down a much larger query that was
> exhibiting the behavior to what appears to be the cause). I know that
> views have some limitations, and two of the relations used are views, so I
> belive that that may be the problem, but I want to be sure...

Grouped views don't really work in 7.0.* or prior releases, except in
the very simplest cases. The query rewriter basically just does "macro
expansion" of the view into your query, so unless you can write out the
equivalent query as valid SQL without using views, it won't work. In
particular, selecting simultaneously from two views with different
grouping requirements cannot work, because there's only one GROUP BY
phase available. Unfortunately, the rewriter is too stupid to notice
that it can't produce a correct translation :-(

This is fixed in current sources --- a grouped view will be done as
a true sub-query.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alfred Perlstein 2000-10-09 02:54:59 Re: Still crashing with latest 7.0.2 (Re: (forw) more crashes)
Previous Message Bruce Momjian 2000-10-09 02:32:24 Re: C++ client libs