Am 11.09.2013 um 17:31 schrieb Andrew Dunstan <and...@dunslane.net>: > I recently had to diagnose and remedy a case such as this. > > The short answer is to rewrite your query so you don't have to group by so > many things. Collect your aggregates in a common table expression query (or > possibly more than one, depends what you need) using the minimum > non-aggregated columns to enable you to get correct results and then later > decorate that with all the extra things you need such as constant columns and > columns that are irrelevant to the aggregation. > > This gets hard when queries are very complex, and harder still when the query > is written by a query generator. But a good generator should not just say > "grouo by everything that's not aggregated" and think it's doing a good job. > In your case it should be relatively straightforward. > > cheers > > andrew
Ah, yes, only now do I see that the query screams for a CTE. Thanks for the eye opener. Maximilian Tyrtania http://www.contactking.de -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance