Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers
От | Tom Lane |
---|---|
Тема | Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers |
Дата | |
Msg-id | 1102.1304649395@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers (Josh Kupershmidt <schmiddy@gmail.com>) |
Ответы |
Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers
|
Список | pgsql-docs |
Josh Kupershmidt <schmiddy@gmail.com> writes: > [Moving to -docs] > On Mon, May 2, 2011 at 12:00 PM, Pavel Stehule <pavel.stehule@gmail.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
В списке pgsql-docs по дате отправления: