From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Bill Moseley <moseley(at)hank(dot)org> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Trigger for Audit Table |
Date: | 2007-03-10 01:40:05 |
Message-ID: | 6047.1173490805@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Bill Moseley <moseley(at)hank(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Bruno Wolff III | 2007-03-10 02:00:12 | Re: Setting week starting day |
Previous Message | Jeff Davis | 2007-03-10 01:16:13 | Re: Statistics |