I have a bunch of different tables in my database, all of them have a gist index and I want to know of two tables have data in the same area. So what is the easiest way to get the extent of the geometry?

Some tables have a column with points and some tables have a column with polygons..


you can use ST_EXTENT on the tables to get their bounding box, and ST_INTERSECTS to know if they do intersect or not. Note that it is a bounding box intersect, not a geometry intersect.

select st_asText(st_extent(geom)) from myLayer;

select st_intersects(a.geom,b.geom) from 
  (select st_extent(geom) geom from layer1) a,
  (select st_extent(geom) geom from layer2) b;
  • Sweet I tried with select st_intersects(st_extent(ac.geom), st_extent(ha.geom)) from activity.talble_a ac, harvest.table_h ha but it didn't work, your solution works nice and fast!
    – axel_ande
    Apr 12 '18 at 4:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.