From: | Luca Pireddu <luca(at)cs(dot)ualberta(dot)ca> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | bug or not? Trigger preventing delete causes circumvention of FK |
Date: | 2005-12-09 02:12:25 |
Message-ID: | 200512081912.25883.luca@cs.ualberta.ca |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I wrote a trigger function with the intent of preventing the deletion of a
parent record when a referencing record would not allow it. However, the
result is that the referencing record stays, but the referenced one is gone,
so that my foreign key constraint is not respected. The behaviour can be
replicated with the following:
create table parent(id serial primary key);
create table dependent (id integer primary key references parent on delete
cascade);
create or replace function check_delete() returns trigger as $$
BEGIN
if TG_OP = 'DELETE' then
raise notice 'preventing delete';
return null;
else
return OLD;
end if;
END;
$$
language 'plpgsql';
CREATE TRIGGER trig_check_delete BEFORE DELETE ON dependent
FOR EACH ROW EXECUTE PROCEDURE check_delete();
insert into parent values(1);
insert into dependent values(1);
delete from parent;
The record in the dependent table is left behind, while the referenced parent
is gone. Is this a bug?
I'm using PostgreSQL version 8.0.4 on Linux.
Luca
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2005-12-09 02:17:47 | Re: bug or not? Trigger preventing delete causes circumvention of FK |
Previous Message | Dann Corbit | 2005-12-09 01:48:37 | Re: copy with where query? |