X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id C334CD1B1C7 for ; Fri, 21 May 2004 12:29:18 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 09831-10 for ; Fri, 21 May 2004 12:28:58 -0300 (ADT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id D096FD1C4DB for ; Fri, 21 May 2004 12:28:57 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i4LFSqQn004043; Fri, 21 May 2004 11:28:52 -0400 (EDT) To: Jeff Post Cc: pgsql-sql@postgresql.org Subject: Re: Preventing Deletions with triggers 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> Comments: In-reply-to Jeff Post message dated "Wed, 19 May 2004 09:19:47 -0500" Date: Fri, 21 May 2004 11:28:52 -0400 Message-ID: <4042.1085153332@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200405/199 X-Sequence-Number: 17913 Jeff Post 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