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

Поиск
Список
Период
Сортировка
От Terry Lee Tucker
Тема Re: Sequences, triggers and 'OLD' - am I being stupid?
Дата
Msg-id 200510070919.24272.terry@esc1.com
обсуждение исходный текст
Ответ на Sequences, triggers and 'OLD' - am I being stupid?  ("Steve South" <steve.south@blueyonder.co.uk>)
Ответы Re: Sequences, triggers and 'OLD' - am I being stupid?  ("Steve South" <steve.south@blueyonder.co.uk>)
Список 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 по дате отправления:

Предыдущее
От: "Steve South"
Дата:
Сообщение: Sequences, triggers and 'OLD' - am I being stupid?
Следующее
От: "Steve South"
Дата:
Сообщение: Re: Sequences, triggers and 'OLD' - am I being stupid?