Received: from server0.telegraafnet.nl (firewall.telegraafnet.nl [195.64.78.58]) by postgresql.org (8.11.3/8.11.4) with ESMTP id fAKFmMm30058 for ; Tue, 20 Nov 2001 10:48:23 -0500 (EST) (envelope-from ferdinand@telegraafnet.nl) Received: from server9.telegraafnet.nl (server9.telegraafnet.nl [192.168.1.9]) by server0.telegraafnet.nl (8.9.3/8.9.3) with ESMTP id QAA16191; Tue, 20 Nov 2001 16:48:26 +0100 Received: from there (c22457.ws.tem.nl [192.168.1.26]) by server9.telegraafnet.nl (8.11.1/8.11.1/Debian 8.11.0-6) with SMTP id fAKFmPS03986; Tue, 20 Nov 2001 16:48:25 +0100 Message-Id: <200111201548.fAKFmPS03986@server9.telegraafnet.nl> X-Authentication-Warning: server9.telegraafnet.nl: Host c22457.ws.tem.nl [192.168.1.26] claimed to be there Content-Type: text/plain; charset="iso-8859-1" From: Ferdinand Smit To: Mr OCP , pgsql-admin@postgresql.org Subject: Re: Please help Date: Tue, 20 Nov 2001 16:44:19 +0100 X-Mailer: KMail [version 1.3.2] References: <20011116021806.20613.qmail@web20606.mail.yahoo.com> In-Reply-To: <20011116021806.20613.qmail@web20606.mail.yahoo.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Archive-Number: 200111/95 X-Sequence-Number: 2620 Hi Mike, > Can anyone help me write a trigger on a table, I have > created an audit table for a table and what I want > trigger to do is to whenever a record is deleted from > the table it should first be inserted into the audit > table, just to keep track of whatever records are > deleted. Is this something ?? This archives my adres changes. /* Archive function */ DROP FUNCTION fn_archive(); CREATE FUNCTION fn_archive() RETURNS OPAQUE AS ' BEGIN /* TG_OP is the function (UPDATE, DELETE, SELECT) */ INSERT INTO adres_archive VALUES (OLD.name,OLD.adres,OLD.tel,current_user,now(),tg_opt); NEW.modtime := ''now''; END IF; RETURN NEW; END; ' LANGUAGE 'plpgsql'; /* Archive trigger */ DROP TRIGGER tr_archive ON adres; CREATE TRIGGER tr_adres_archive BEFORE UPDATE OR DELETE ON adres FOR EACH ROW EXECUTE PROCEDURE fn_archive (); Ferdinand Smit