From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Teemu Juntunen" <teemu(dot)juntunen(at)e-ngine(dot)fi> |
Cc: | pgsql-general(at)postgreSQL(dot)org |
Subject: | Re: After delete trigger problem |
Date: | 2008-11-08 18:18:11 |
Message-ID: | 19209.1226168291@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"Teemu Juntunen" <teemu(dot)juntunen(at)e-ngine(dot)fi> writes:
> -- Trigger at the child table
> CREATE TRIGGER "AFTER_DELETE_CHILD"
> AFTER DELETE
> ON child
> FOR EACH ROW
> EXECUTE PROCEDURE fn_checkmaster();
> -- This example leads to an exception
> INSERT INTO master (foo) VALUES (1);
> INSERT INTO child (foo,hoo) VALUES (1,1);
> DELETE FROM master WHERE foo=1;
Oh, I see the problem: the trigger's on the wrong table. What you've
got here is:
* delete a master row
* after that, the FK trigger on the master fires and issues a DELETE
against affected rows of the child table
* this deletes a child row
* after that, your trigger fires
Basically there's no way for a trigger on the child to see the master
row still there, because it's already gone before any action is taken
against the child. Even a BEFORE DELETE trigger would run too late.
You might be able to do something with a delete trigger on the
master table ...
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Gregory S. Youngblood | 2008-11-08 20:56:14 | Last Week to Participate in PostgreSQL Certification JTA Survey |
Previous Message | Tom Lane | 2008-11-08 17:57:15 | Re: Fulltext index |