Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Postgres 8.4 PostGIS 2.0 enabled database and I've loaded it up with a bunch of shapefiles.

I'm trying to get the database to do on-the-fly unions of geometries.

Here is the query I'm working with:

SELECT ST_AsGeoJSON(ST_Union(the_geom)) FROM (SELECT geom FROM forecast_zones WHERE 
state = 'ND' AND zone IN ('002','011','021','035','046','050')) as the_geom;

The Subquery to pull the geometries of the individual zones works fine:

SELECT geom FROM forecast_zones WHERE state = 'ND' AND zone IN 

But whenever I try to pass that to ST_Union I get undefined function errors.


Here is the query I ended up using that works:

SELECT ST_AsGeoJSON(ST_Union(forecast_zones.geom)) AS geom FROM forecast_zones
WHERE forecast_zones.state = 'ND' AND IN
GROUP BY forecast_zones.state
share|improve this question
up vote 1 down vote accepted

This is a query I use to merge all 'elementary school boundary' features into a single boundary based on their name. this essentially does a dissolve of all chunks of elementary boundaries by their name, and gives me back a table of unioned boundaries. we would do this for middle and high schools too...

select elm_school as name, st_union(allbounds2012.geom) as geom
from allbounds2012
where allbounds2012.elem_num > 0
group by allbounds2012.elm_school;
  • gets the name of the elementary school from allbounds2012
  • unions the geometry of the boundaries in allbounds2012 (where the elem_num(school number) is greater than 0
  • groups (unions) them by their name
share|improve this answer
This TOTALLY worked, thank you so much! – DirtyBirdNJ Aug 1 '13 at 19:14
awesome! you're welcome!!! – DPSSpatial Aug 1 '13 at 20:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.