Re: partial "on-delete set null" constraint

From: Rafal Pietrak <rafal(at)ztk-rp(dot)eu>
To: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: partial "on-delete set null" constraint
Date: 2015-02-15 17:14:46
Message-ID: 54E0D406.5050502@ztk-rp.eu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


W dniu 03.02.2015 o 04:44, Jim Nasby pisze:
> On 1/3/15 2:49 AM, Rafal Pietrak wrote:
>>
[-----------------------]
>> But an application could do
>> ---------a successfull scenario with expected result-------------------
>> testvm=# UPDATE mailboxes SET username = null;
>> UPDATE 1
>> testvm=# DELETE FROM mailusers ;
>> DELETE 1
>> -----------------------------------------------------------
>> Which works just fine.
>>
>> So I add a TRIGER BEFORE, to have the above first statement get executed
>> just like in the above example: before the actual DELETE:
>> ----------------------
>> CREATE or replace FUNCTION prepare_null () returns trigger language
>> plpgsql as $$ begin old.username=null; return old; end; $$;
>> CREATE TRIGGER prepare_null BEFORE DELETE On mailusers for each row
>> execute procedure prepare_null();
>> -----------------------------
>
> That trigger function is NOT doing the same thing as above. What you
> want is something that does UPDATE mailboxes SET username = null WHERE
> username = OLD.username. You'd need to make sure that trigger ran
> before the RI trigger did.

Oh. yes. It actually does work. Silly me making such obvious mistakes.

Nonetheless I stand my grounds on the FK internal functionality opinion,
in that if FK constraint internal triggers would SET NULL (when cascaded
set null is declared) only those columns of the target, that are
actually NULL-able, then the coding (SQL application programmer's life
like myown) would get easier in such usage scenarios.

thenx anyway!

-R

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Eugene Dzhurinsky 2015-02-15 17:29:10 Re: Import large data set into a table and resolve duplicates?
Previous Message John McKown 2015-02-15 16:04:22 Re: Import large data set into a table and resolve duplicates?