Can I execute something like this in Postgresql, that is, execute CASCADE DELETE for just one statement?
DELETE CASCADE FROM foo WHERE bar = 'baz';
My goal is to delete not just the selected record(s) from table foo, but all the records in all the tables where foo.id column is used as a foreign key, without adding the constraint for the entire table foo: ON DELETE CASCADE.
Related:
- postgresql - CASCADE DELETE just once - Stack Overflow - a similar question was asked in 2008. I wonder if anything has changed since then.
- Deleting a row in one table should also delete the corresponding rows in another table - I want to avoid this, since it
ALTERs the entire table, and affects all theDELETEstatements. I want to do something like this, but on a per statement basis. - PostgreSQL: Documentation: 16: 5.4. Constraints - could not find an answer in the docs.
- Is it a good or bad idea to use "ON UPDATE CASCADE ON DELETE CASCADE" for foreign keys? Why does this mechanism exist at all? - The pros and cons of
ON DELETE CASCADEare discussed in the answers in this Q&A.