Re: problem with subselect - Mailing list pgsql-sql

From Josh Berkus
Subject Re: problem with subselect
Date
Msg-id 200303070948.45070.josh@agliodbs.com
Whole thread Raw
In response to problem with subselect  (Mathieu Arnold <mat@mat.cc>)
Responses Re: problem with subselect  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
Mathieu,

> SELECT   date_trunc('month', f.date_creation) as mois,
>          sum(f.montant_ttc / d.taux) as facture,
>          (SELECT  sum(f2.montant_ttc / d2.taux) as facture2
>           FROM facture AS f2 JOIN devise AS d2 USING (id_devise)
>           WHERE date_trunc('month', f2.date_creation)
>                 <= date_trunc('month', f.date_creation))
> FROM   facture AS f JOIN devise AS d USING (id_devise)
> GROUP BY   date_trunc('month', f.date_creation)

> "Sub-SELECT uses un-GROUPed attribute f.date_creation from outer query"
> Which is not really true, but some way is...

Hmmm ... this looks like a minor parser bug.  What Postgres version are you 
using?

> What I want is to get the sum of the month, and the sum of the month and
> the previous.
>
> If someone has a clue, something, anything... :)

Sure.  Try putting the sub-select in the FROM clause, instead of the SELECT; 
that should un-confuse the parser about the grouping.

-- 
Josh Berkus
Aglio Database Solutions
San Francisco


pgsql-sql by date:

Previous
From: Josh Berkus
Date:
Subject: Re: How to notice column changes in trigger
Next
From: Andreas Pflug
Date:
Subject: Re: How to notice column changes in trigger