Re: Sequences, triggers and 'OLD' - am I being stupid?

From: Terry Lee Tucker <terry(at)esc1(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Sequences, triggers and 'OLD' - am I being stupid?
Date: 2005-10-07 13:19:24
Message-ID: 200510070919.24272.terry@esc1.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Steve,

I'm not quite sure I understand. It seems that the trigger should be on table
T1 not T2. The trigger should fire on an update to T1.

Regardless of that, OLD is only available during an UPDATE or DELETE
operations. OLD is NOT available during an INSERT operation. NEW is available
in all three instances. Use TG_OP to distinguish what is happening and then
don't use references to OLD in the INSERT block.

IF TG_OP = ''Insert'' THEN
<only references to NEW here>
ELSIF TG_OP = ''UPDATE'' THEN
<references to both OLD and NEW here>
END IF;

You might need to post some of the code.

HTH.

On Friday 07 October 2005 08:59 am, Steve South saith:
> I'll admit straight away I'm a novice, but this one has me perplexed....
>
> I have a table, T1, with a column (userid) that is an int4 generated from a
> sequence.
>
> I have a second table (T2) that I wish to use to hold audited values from
> T1.
>
> I have created a trigger function written in PL/PGSQL, set to be for each
> row after update on T2, which is supposed to copy the OLD values into T2.
>
> The snag is that when I try to update a row in T1 I get:
>
> ERROR: record "old" has no field "userid"
>
> This behaviour does not seem to be documented anywhere. Am I just being
> dense?
>
> TIA,
>
> Steve S
>
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.344 / Virus Database: 267.11.13/123 - Release Date: 06/10/2005
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster

--

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Steve South 2005-10-07 13:47:39 Re: Sequences, triggers and 'OLD' - am I being stupid?
Previous Message Steve South 2005-10-07 12:59:40 Sequences, triggers and 'OLD' - am I being stupid?