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 7459ED1B4A8 for ; Fri, 21 May 2004 12:03:32 -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 92827-07 for ; Fri, 21 May 2004 12:03:10 -0300 (ADT) Received: from conexa.fciencias.unam.mx (conexa.fciencias.unam.mx [132.248.181.120]) by svr1.postgresql.org (Postfix) with ESMTP id 80658D1B18A for ; Fri, 21 May 2004 12:03:09 -0300 (ADT) Received: from conexa.fciencias.unam.mx (conexa.fciencias.unam.mx [127.0.0.1]) by conexa.fciencias.unam.mx (8.12.8/8.12.8) with ESMTP id i4LF1LqJ010724; Fri, 21 May 2004 10:01:21 -0500 Received: (from masm@localhost) by conexa.fciencias.unam.mx (8.12.8/8.12.8/Submit) id i4LF1L74010722; Fri, 21 May 2004 10:01:21 -0500 X-Authentication-Warning: conexa.fciencias.unam.mx: masm set sender to masm@fciencias.unam.mx using -f To: Jeff Post Cc: pgsql-sql@postgresql.org Subject: Re: Preventing Deletions with triggers References: <6.1.0.6.0.20040519090934.025963a8@mail.milwaukee.k12.wi.us> In-Reply-To: <6.1.0.6.0.20040519090934.025963a8@mail.milwaukee.k12.wi.us> From: Manuel Sugawara User-Name: Manuel Sugawara User-Mail-Address: masm@fciencias.unam.mx Date: 21 May 2004 10:01:20 -0500 Message-ID: Lines: 33 User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Portable Code) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.1 tagged_above=0.0 required=5.0 tests=RCVD_IN_RFCI X-Spam-Level: X-Archive-Number: 200405/197 X-Sequence-Number: 17911 Jeff Post 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.