We have some tables that don't have cascade set up, but we'd like to manually clean them up with one command when a project is deleted.
For example, to delete the Permissions table and the Votes table based on the project with identifier = 'abcdefg', we'd like to first look up the project's id and then use that to delete the tables in question:
WITH proj_id AS (
SELECT id FROM "Projects" WHERE identifier = 'abcdefg'
)
DELETE FROM "Permissions" WHERE project_id IN (proj_id);
DELETE FROM "Votes" WHERE project_id IN (proj_id);
DELETE FROM "Gadgets" WHERE project_id IN (proj_id);
...
DELETE FROM "Projects" WHERE id IN (proj_id);
This doesn't work, but I think it illustrates the goal.
Is there a way to accomplish this DELETE across multiple tables, without writing the identifier value more than once?