Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id A35DE1337BA3 for ; Thu, 5 May 2011 23:36:43 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 18854-05 for ; Fri, 6 May 2011 02:36:38 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id D35B51337B97 for ; Thu, 5 May 2011 23:36:35 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p462aZWe001104; Thu, 5 May 2011 22:36:35 -0400 (EDT) To: Josh Kupershmidt cc: Pavel Stehule , pgsql-docs Subject: Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers In-reply-to: References: Comments: In-reply-to Josh Kupershmidt message dated "Thu, 05 May 2011 20:56:36 -0400" Date: Thu, 05 May 2011 22:36:35 -0400 Message-ID: <1102.1304649395@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201105/15 X-Sequence-Number: 6690 Josh Kupershmidt writes: > [Moving to -docs] > On Mon, May 2, 2011 at 12:00 PM, Pavel Stehule 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