Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, pgsql-docs <pgsql-docs(at)postgresql(dot)org>
Subject: Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers
Date: 2011-05-06 02:36:35
Message-ID: 1102.1304649395@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-docs

Josh Kupershmidt <schmiddy(at)gmail(dot)com> writes:
> [Moving to -docs]
> On Mon, May 2, 2011 at 12:00 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>> It isn't correct. NEW is not declared in DELETE trigger, OLD isn't
>> declared in INSERT

That claim is flat out wrong.

> If I've understood you correctly, the problem is that the docs claim
> that the variables are defined with a value of NULL, when in fact they
> are undefined. For example, if you try to use variable NEW in a delete
> trigger, you'll get an error message like:
> | ERROR: record "new" is not assigned yet
> | DETAIL: The tuple structure of a not-yet-assigned record is indeterminate.

That is, in fact, exactly the behavior you get if you declare a RECORD
variable and set it to NULL. If these variables were indeed not
declared, you'd get a complaint about "new" not being a known variable.
Observe:

regression=# create function foo(int) returns void as $$
regression$# begin
regression$# new.x := $1;
regression$# end$$ language plpgsql;
ERROR: "new.x" is not a known variable
LINE 3: new.x := $1;
^

versus

regression=# create function foo(int) returns void as $$
regression$# declare new record;
regression$# begin
regression$# new := null;
regression$# new.x := $1;
regression$# end$$ language plpgsql;
CREATE FUNCTION
regression=# select foo(1);
ERROR: record "new" is not assigned yet
DETAIL: The tuple structure of a not-yet-assigned record is indeterminate.
CONTEXT: PL/pgSQL function "foo" line 5 at assignment

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Josh Kupershmidt 2011-05-06 02:58:24 Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers
Previous Message Pavel Stehule 2011-05-06 02:31:35 Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers

Browse pgsql-docs by date

  From Date Subject
Next Message Josh Kupershmidt 2011-05-06 02:58:24 Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers
Previous Message Pavel Stehule 2011-05-06 02:31:35 Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers