Re: Sequences, triggers and 'OLD' - am I being stupid? - Mailing list pgsql-novice

From Terry Lee Tucker
Subject Re: Sequences, triggers and 'OLD' - am I being stupid?
Date
Msg-id 200510070919.24272.terry@esc1.com
Whole thread Raw
In response to Sequences, triggers and 'OLD' - am I being stupid?  ("Steve South" <steve.south@blueyonder.co.uk>)
Responses Re: Sequences, triggers and 'OLD' - am I being stupid?  ("Steve South" <steve.south@blueyonder.co.uk>)
List 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

--

pgsql-novice by date:

Previous
From: "Steve South"
Date:
Subject: Sequences, triggers and 'OLD' - am I being stupid?
Next
From: "Steve South"
Date:
Subject: Re: Sequences, triggers and 'OLD' - am I being stupid?