In PL/pgSQL trigger function, is there a way to know that the deletion was invoked by cascading delete action?
I have a number of checks in a trigger function to see if deletion is allowed, which I don't want to perform if the deletion is cascading from master table.
Asked
Active
Viewed 857 times
4

Erwin Brandstetter
- 605,456
- 145
- 1,078
- 1,228

Nikša Baldun
- 1,854
- 4
- 28
- 39
1 Answers
4
I can't think of a built-in way to check that.
You could instead check for existence of the master row in the master table ...
IF EXISTS (
SELECT 1
FROM master_table m
WHERE m.master_id = OLD.master_id) THEN
-- run checks
END IF;
If it's a cascading delete the master row should be gone already.

Erwin Brandstetter
- 605,456
- 145
- 1,078
- 1,228
-
Of course! I should have thought of that. I will try it now. – Nikša Baldun Jun 18 '14 at 17:22