Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 212A06329D8 for ; Fri, 3 Sep 2010 14:58:38 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 44892-07 for ; Fri, 3 Sep 2010 17:58:30 +0000 (UTC) X-Greylist: delayed 00:07:20.187282 by SQLgrey-1.7.6 Received: from www1.brickcitywebs.net (www1.brickcitywebs.net [8.8.67.10]) by mail.postgresql.org (Postfix) with ESMTP id BDD5363267E for ; Fri, 3 Sep 2010 14:58:30 -0300 (ADT) Received: (qmail 12258 invoked from network); 3 Sep 2010 16:51:56 -0500 Received: from softdnserror (HELO outlook.rad-con.com) (12.49.144.162) by www1.brickcitywebs.net with SMTP; 3 Sep 2010 16:51:56 -0500 Content-class: urn:content-classes:message Subject: Re: fail-safe sql update triggers MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Date: Fri, 3 Sep 2010 13:50:54 -0400 X-MimeOLE: Produced By Microsoft Exchange V6.5 Message-ID: <04A6DB42D2BA534FAC77B90562A6A03D015542F9@server.rad-con.local> In-Reply-To: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [ADMIN] fail-safe sql update triggers thread-index: ActLaGE7yth5dRHmSFe80/zY0jK71QAJ15UQ References: From: "Rob Richardson" To: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201009/38 X-Sequence-Number: 35582 =20 I thought I sent this earlier, but it's not in my Sent box, so I'll try again. Your solution maintains an exact copy of two tables. Whenever a record is updated in the first, it is updated in the second, and you have lost information about the previous value. Whenever I do anything like this, I have three triggers on the source table, one each for insert, update and delete. The history table has the same columns as the source table, plus two more, one named "action" and the other named "event_time". The event_time field defaults to the current time. The bodies of the three trigger functions are: insert into history select new.*, 'Insert' insert into history select new.*, 'Update' insert into history select old.*, 'Delete' That way, I can track everything that happened in my source table. Typically, there's something else, like maybe another trigger, that deletes old records from the history table. I hope this helps! RobR