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;

Answers


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;

Need Your Help

Multi-bit database field

sql-server database field

I'm using a MSSQL database and would like to create a column that only has 4 possible values. Is there any way to define a 2-bit column? I see the bit datatype and then the next smallest is tin...