Re: [BUGS] bug in views/aggregates - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [BUGS] bug in views/aggregates
Date
Msg-id 4048.972529268@sss.pgh.pa.us
Whole thread Raw
List pgsql-hackers
Kovacs Zoltan Sandor <tip@pc10.radnoti-szeged.sulinet.hu> writes:
> I'm not sure if this is a reported bug or not. SELECT statements with some
> aggregates on certain complex views can give terrible results. An example:

Aggregates on grouped views do not and cannot work in 7.0 or earlier
releases, because the existing rewriter implementation cannot cause the
system to do multiple rounds of grouping/aggregation.  Unfortunately
the rewriter is usually not bright enough to realize it can't do the
right thing, either :-(

This is fixed for 7.1.  In current sources your example produces

regression=# SELECT count(*) FROM buggy_view;count
-------    2
(1 row)

> I am interested in workarounds as well.

For now, you could select the view's results into a temp table,
and then aggregate over the table.
        regards, tom lane


pgsql-hackers by date:

Previous
From: "andres mackiewicz"
Date:
Subject: DBD::Pg::st execute failed: ERROR
Next
From: Kovacs Zoltan Sandor
Date:
Subject: bug in views/aggregates