Re: unexpected 'aggregates not allowed in where clause' error

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "L(dot) Fletcher" <lucasf(at)vagabond-software(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: unexpected 'aggregates not allowed in where clause' error
Date: 2005-03-03 19:15:59
Message-ID: 10312.1109877359@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"L. Fletcher" <lucasf(at)vagabond-software(dot)com> writes:
> I am getting a strange "aggregates not allowed in where clause" error =
> when I try to execute the below query:

> SELECT n.note, pr.property_id AS PropertyID
> FROM property.note n
> INNER JOIN property.rating_note rn ON rn.note_id =3D n.note_id
> INNER JOIN property.propertyrating pr ON pr.property_rating_id =
> =3D rn.property_rating_id
> WHERE pr.property_id IN
> (
> SELECT p.property_id
> FROM property.vw_property_summary p
> INNER JOIN property.propertyscore ps ON p.property_id =3D =
> ps.property_id
> WHERE (ps.score_type_id =3D $1 AND p.place_id =3D $2)
> OR (ps.score_type_id =3D $3 AND p.place_id =3D $4)
> )
> AND pr.created_date >=3D
> (
> SELECT MIN(pr.created_date) FROM property.propertyrating pr2
> WHERE pr2.property_rating_id =3D pr.property_rating_id
> ORDER BY pr.created_date DESC LIMIT 5
> );

The error message is correct, because the aggregate is associated with
the outer query's pr table. Perhaps you meant to write
"MIN(pr2.created_date)"?

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message OpenMacNews 2005-03-03 19:28:33 Changing Run-time parameters at command line
Previous Message Mark 2005-03-03 19:07:53 hostname change and postgresql