1

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;

1 Answer 1

2

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.