From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jeff Post <POSTJL@milwaukee.k12.wi.us>
Cc: pgsql-sql@postgresql.org
Subject: Re: Preventing Deletions with triggers
Date: Fri, 21 May 2004 11:28:52 -0400
Message-ID: <4042.1085153332@sss.pgh.pa.us> (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:
> 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';
> create trigger person_fake_delete
> before delete on person
> for each row EXECUTE PROCEDURE
> person_fake_delete();
> This however does not work. the tupple is still deleted from the
> table. Any Ideas?
It works for me, in the sense that returning NULL prevents the
deletion. However that assignment to OLD is a no-op: you can't change
the tuple that way. You'd have to do something like
UPDATE person SET status = 1 WHERE key = OLD.key;
("key" being whatever your primary key for the table is)
regards, tom lane
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: tgl@sss.pgh.pa.us, POSTJL@milwaukee.k12.wi.us
Subject: Re: Preventing Deletions with triggers
In-Reply-To: <4042.1085153332@sss.pgh.pa.us>
* 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