Thread: DELETE and UPDATE in same function with foriegn keys

DELETE and UPDATE in same function with foriegn keys

From
Robert Fitzpatrick
Date:
I have tblhud74b that has a foreign key to tblhudunits with Restrict
Updates. I have a function that DELETEs corresponding records before
doing an UPDATE right after the DELETE statement and receive the
following error:

ERROR:  update or delete on "tblhudunits" violates foreign key
constraint "tblhudunitstblhud74b_fk" on "tblhud74b"
DETAIL:  Key (similar_group_id,sort_order)=(18,1) is still referenced
from table "tblhud74b".

It seems the DELETE is not posted before the UPDATE happens, hence the
error, right? I tried setting the Foreign Key to DEFERRABLE INITIALLY
DEFERRED, but does not seem to work. Is there a way to do this without
having to set my Foreign Key to Update instead of Restrict. That works
if I do that.

--
Robert