[postgis-users] left outer join not working as expected with ST_Contains

Arne Kepp arne at tiledmarble.org
Wed Jan 12 02:49:25 PST 2011


Hi,

let me prefix by saying that I am not very good with SQL, so that's 
probably where the problem lies, but it seems like ST_Contains always 
ends up giving me a cross join.

SELECT sample_id, sample_date, ST_AsText(point_layer.the_geom), 
polygon_value
FROM point_layer
LEFT OUTER JOIN polygon_layer ON ST_Contains(polygon_layer.the_geom, 
point_layer.the_geom)
WHERE point_layer.active = 1

In plain text: I have a table of points and a table of polygons. The 
polygons have a column "polygon_value" that I would like to report with 
each point.

The problem is that more than one polygon can contain the point. This is 
not a problem for me, as long as I can get polygon_value from one of 
them. But the query above produces one row for every point/polygon 
combination. So it's essentially behaving like a cross join?

Any suggestions on what I am doing wrong or how I can get the result I 
am after? Using Postgis 1.3.6 on Postgresql 8.4.4

Thank you,
-Arne



More information about the postgis-users mailing list