views:

53

answers:

1

In the title is what I need.

CREATE TABLE newTable1 AS SELECT t2.name,t2.the_geom2
FROM t1,t2
WHERE ST_Contains(ST_Expand(t2.the_geom2,0.05),t1.the_geom1) 
      and t1.gid=2;

CREATE TABLE newTable2 AS SELECT t1.the_geom,t1.label FROM t1 WHERE t1.gid=2;

First query result is all points within polygon and apart from it for 5min where this polygon has gid=2. But I also want to display this polygon. I tried to write in first query

... AS SELECT t2.name,t2.the_geom2,t1.the_geom1,t1.label ...but got only points without polygon...

This question is linked with already asked question "How to find all points away from some polygon?". But didn't get answere, so please...

And is ST_expand ok solution or it will be better to use ST_DWithin or ST_buffer ?

+1  A: 

You can't combine two CREATE TABLE statements into one. Why are you creating tables if you are just querying data?

It sounds like what you are really trying to do is one query that will give you the points within the polygon and the polygon itself. Something like this?

SELECT
    t1.the_geom AS polygon, t1.label AS polygon_label, 
    t2.the_geom2 AS point, t2.name AS point_name
FROM
    t1, t2
WHERE
    ST_Contains(ST_Expand(t2.the_geom2,0.05), t1.the_geom1) 
    AND t1.gid = 2;

If this is still not clear, post your complete table definitions and more details about what you are trying to do.

cope360