From: Manuel Sugawara <masm@fciencias.unam.mx>
To: Jeff Post <POSTJL@milwaukee.k12.wi.us>
Cc: pgsql-sql@postgresql.org
Subject: Re: Preventing Deletions with triggers
Date: 21 May 2004 10:01:20 -0500
Message-ID: <m3fz9t4yf3.fsf@conexa.fciencias.unam.mx> (raw)
In-Reply-To: <6.1.0.6.0.20040519090934.025963a8@mail.milwaukee.k12.wi.us>
References: <6.1.0.6.0.20040519090934.025963a8@mail.milwaukee.k12.wi.us>
Jeff Post <POSTJL@milwaukee.k12.wi.us> writes:
> Here is what I got:
>
> CREATE or replace FUNCTION person_fake_delete() RETURNS TRIGGER AS '
> BEGIN
> OLD.status := 1; -- This does the fake deletion
> RETURN NULL; -- I thought this would prevent the delete from
> actually happening.
>
> END;
> ' LANGUAGE 'plpgsql';
You need to explicitly update the row because changes to the OLD
reference will be lost, for instance:
CREATE or replace FUNCTION person_fake_delete() RETURNS TRIGGER AS '
BEGIN
UPDATE your_table SET status = 1 WHERE primary_key = OLD.primary_key;
RETURN NULL; -- I thought this would prevent the delete from actually happening.
END;
' LANGUAGE 'plpgsql';
> This however does not work. the tupple is still deleted from the table.
> Any Ideas?
Really?, The tuple is still deleted? There should be something that you are
not telling us (may be you are creating the trigger to run AFTER instead of
BEFORE). It have worked for me in each version since the trigger system
were added to postgres.
Regards,
Manuel.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: masm@fciencias.unam.mx, POSTJL@milwaukee.k12.wi.us
Subject: Re: Preventing Deletions with triggers
In-Reply-To: <m3fz9t4yf3.fsf@conexa.fciencias.unam.mx>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox