1
votes

I have a postgis spatial table with polygons in it, having an id (gid) and a geometry column named way (which actually stores the polygon boundary). The tablehead looks as follows:

|| gid (integer) | way (geometry) ||

Every column in this table is representing a polygon. Now I want to take two specific polygons out of this table (select them by the gid) and use ST_Contains() to test if one is contained by the other.

What is the SQL Syntax for this?

1
Are {polygon1, polygon2} actual columns of the polygon_table ? Please add the table definition to your question. The question is not very clear either; you want to check if two records have overlapping/intersecting polygons? - wildplasser
I have edited the question. I hope it is clearer now. - Michbeckable
In short: you want to select two records and compare them. - wildplasser
Yes. Currently I use ST_Contains(geometry1, geometry2) by giving the geometry data directly into it: ST_Contains(ST_GeomFromText(...), ST_GeomFromText(...)). But now I want to select two rows (polygons) of the table and put their geometry column ("way") into ST_Contains. - Michbeckable

1 Answers

3
votes

Try the following:

SELECT st_contains(a.way, b.way)
FROM yourtable AS a, yourtable AS b
WHERE 
    a.gid = yourfirstid
    AND b.gid = yoursecondid

Is that all you wanted to know, or did I misinterpret the question?