Thread: [NOVICE] trigger on delete/field update

[NOVICE] trigger on delete/field update

From
Ruslan R. Laishev
Date:
Hi All!
 
I have tried to set a flag ('deleted' ) instead of actual record deletion, so I have tried to accomplish it with next piece of code in the trigger:
 
BEGIN
/*
**  Description: disable  deletion of the rows from the table,
**    instead we set .deleted flag to 1
*/
 
        IF (TG_OP = 'DELETE') THEN
         UPDATE v.comps SET deleted = 1 WHERE v.comps.id = OLD.id;
                RETURN NULL;
        END IF;
 
END;
 
 
DELETE row on the table v does not generate any error, but row still here and 'deleted' field has not been set to 1 as expected.
So, what I'm need to check ?
 
 
 
TIA.
 
-- 
С уважением,
Ruslan R. Laishev
OpenVMS bigot, natural born system/network progger, C contractor.
+79013163222
+79910009922
 

Re: [NOVICE] trigger on delete/field update

From
"David G. Johnston"
Date:
On Mon, Oct 16, 2017 at 7:27 AM, Ruslan R. Laishev <zator@yandex.ru> wrote:
So, what I'm need to check ?

​I assume you are using a BEFORE trigger on the table...​

​The docs imply what you want to do is not possible using triggers.


"​Row-level triggers fired BEFORE can return null to signal the trigger manager to skip the rest of the operation for this row (i.e., subsequent triggers are not fired, and the INSERT/UPDATE/DELETE does not occur for this row)."

It might be possible to accomplish your goal with an INSTEAD OF trigger on a View over the table...I have never tried this.


David J.