2

Is there a way to delete data in one table that intersects the geomety of another table? I am using PostGIS.

Effectively I would like to do the following, but this returns an error.

DELETE FROM table_A
WHERE st_intersects(table_A.geom, table_B.geom)

1 Answer 1

9

You need to reference the second table with USING:

DELETE FROM table_A AS a
USING table_B AS b
WHERE ST_Intersects(a.geom, b.geom);

See the docs under 'Notes' for details.

3
  • Nice and straightforward and it works perfectly, thank you!
    – ste_j
    Commented May 24, 2018 at 16:19
  • @ste_j happy to help. care to accept? (wait for 24h according to the boards recommendations, but...)
    – geozelot
    Commented May 24, 2018 at 16:22
  • @ste_j ;) cheers
    – geozelot
    Commented May 24, 2018 at 16:26

Your Answer

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

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