Re: [SQL] Select & Tables X Select & Views - Mailing list pgsql-sql

From Tom Lane
Subject Re: [SQL] Select & Tables X Select & Views
Date
Msg-id 29583.951172028@sss.pgh.pa.us
Whole thread Raw
In response to Re: [SQL] Select & Tables X Select & Views  (Rodrigo Rezende <Rodrigo.Rezende@hortolandia.marelli.it>)
List pgsql-sql
Rodrigo Rezende <Rodrigo.Rezende@hortolandia.marelli.it> writes:
> The view :
> create view func_aux_stat as select fp.codfuncionario, max(fp.data) as
> data from func_preench as fp group by fp.codfuncionario ;

Ah.  I'm afraid GROUP BY doesn't work very well in views --- it's OK
for simply selecting from the grouped view, but not for joining it
against other tables.  This is because the rule rewriter can only
revise your query into some other query that's still expressible in
SQL, and there's no way to group only one table in a query in the
subset of SQL that we support.

We hope to fix this in 7.1, but for now it's not going to work.
You might think about trying to recast your problem to use subselects,
or some other approach that doesn't involve joining a grouped table
against an ungrouped one.
        regards, tom lane


pgsql-sql by date:

Previous
From: Rodrigo Rezende
Date:
Subject: rule plan string too big
Next
From: Peter Eisentraut
Date:
Subject: Re: [SQL] rule plan string too big