![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I'm trying to combind a cascading delete and a constraint deferal. The hope is to have a cascading delete to clean up data, but only after a commit. I can't get it to work. For example in the following code: create temp table primarytest (col2 integer primary key); create temp table defertest( col2 integer references primarytest on update cascade on delete cascade deferrable initially deferred); insert into primarytest values(5); insert into defertest values (5); select * from defertest; begin; set constraints all deferred; delete from primarytest; insert into primarytest values(5); commit; select * from defertest; The row in defertest is deleted even though the value (5) is in primarytest at the end of the session. I was hoping all explicit session transactions would be exceuted prior to nay constraints, but apparently that's not the case. Is there any way to do what I want without changing to an update? |
#3
| |||
| |||
|
|
If you want both ("deferred delete of dependent rows"), I guess you'd have to write it yourself, by using ON DELETE NO ACTION and explicitly deleting the offending dependent rows before COMMIT. |
#4
| |||
| |||
|
|
If you want both ("deferred delete of dependent rows"), I guess you'd have to write it yourself, by using ON DELETE NO ACTION and explicitly deleting the offending dependent rows before COMMIT. Postgres has foreign keys implemented using triggers, which means that this is really not much more expensive than the normal "ON DELETE CASCADE" thing, unless the trigger is messed up and programmed badly. |
![]() |
| Thread Tools | |
| Display Modes | |
| |