Calling returning value from select statement
I need to insert a polygon into a postgresql table "polygontable" and then return its (the_geom) value for further querying. I want to be grabbing the most recently inserted instance in "polygontable". How do I call the returned "polygongeom" in a SELECT statement?
INSERT INTO polygontable (the_geom) VALUES (ST_SetSRID((ST_MakeValid(ST_GeomFromGeoJSON('"+JSON.stringify(payload)+"'))),4326)) returning the_geom as polygon_geom; SELECT st_intersects(polygon_geom, other_table.the_geom) from polygon_geom, other_table;
If you are on 9.1 you can do something like this:
with inserted as ( insert into ... returning the_geom as new_geom ) SELECT st_intersects(inserted.new_geom, other_table.the_geom) from inserted, other_table;