Re: Trigger for Audit Table - Mailing list pgsql-general

From Tom Lane
Subject Re: Trigger for Audit Table
Date
Msg-id 6047.1173490805@sss.pgh.pa.us
Whole thread Raw
In response to Re: Trigger for Audit Table  (Bill Moseley <moseley@hank.org>)
List pgsql-general
Bill Moseley <moseley@hank.org> writes:
> On Fri, Mar 09, 2007 at 06:50:39PM -0500, Tom Lane wrote:
>> This is not going to work because the row's not there yet.

> This is a BEFORE *UPDATE* trigger, not a BEFORE INSERT, so the row is
> there.  The audit table is written when the primary record changes
> and the old version is written to the audit table, not the new
> version.

Well, if you want to write the old data, it's still a silly way to do
it: write the OLD.* tuple instead of forcing a fresh search of the
table.

> Ok, but as the id is a sequence.  I need to test if NEW.id is set after
> the insert -- seems like not, IIRC, and  I'd need to use curval().

You're confusing rules with triggers.  In a trigger, NEW.* and OLD.*
are physical rows and you don't need to worry about multi evaluation
or anything like that.

            regards, tom lane

pgsql-general by date:

Previous
From: Jeff Davis
Date:
Subject: Re: Statistics
Next
From: Bruno Wolff III
Date:
Subject: Re: Setting week starting day