[postgis-users] the_geom must appear in the GROUP BY clause??? (query hangs)

zach cruise zachc1980 at gmail.com
Mon Dec 8 18:14:18 PST 2008


here's a stumper for all you gurus. my working non-geom query is like so:
select
	count(distinct a.id),
	b.fips
from
	a,
	b
where
	a.condition1 = '10'
	and b.condition2 = '20'
group by
	b.fips;
now i want to map this result using b.fips (which is state fips). i
have geom table with fips column, but my queries don't work. i added
like so:
select
	...
	state.fips,
	state.the_geom
from
	...
	state
where
	...
	and state.fips = b.fips
group by
	b.fips;
error: column state.fips and state.the_geom must appear in the GROUP
BY clause or be used in an aggregate function.

but if i add them to the GROUP BY clause, the query hangs.

so my question:
i guess i can't do GROUP BY to the_geom (or 2 distincts), how else do
i write this query? i also tried nesting (...where state.fips in
(subquery)), but it too hangs. DISTINCT ON? here're aggregate
functions but i don't think they'll help -
http://www.postgresql.org/docs/8.1/static/functions-aggregate.html,
http://postgis.refractions.net/documentation/manual-1.3/ch06.html



More information about the postgis-users mailing list