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

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Josh Kupershmidt <schmiddy(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: 2012-08-16 00:31:07
Message-ID: 20120816003107.GA8353@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-docs

On Wed, Sep 7, 2011 at 03:40:19PM +0200, Pavel Stehule wrote:
> 2011/9/7 Josh Kupershmidt <schmiddy(at)gmail(dot)com>:
> > On Tue, Sep 6, 2011 at 10:54 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> >> Josh Kupershmidt wrote:
> >>> How about a doc tweak like the attached?
> >>
> >> Perfect.  Applied to 9.0, 9.1, and head.  Thanks.  Sorry for the delay.
> >
> > Err, as Tom's first comment in this thread explains, Pavel and I were
> > both wrong: the variables in question are indeed NULL, not undefined.
> > I think the docs were fine the way they were.
>
> There is maybe bug - these variables are defined, but they has not
> assigned tupledesc, so there is not possible do any test
>
> postgres=# create table omega (a int, b int);
> CREATE TABLE
> postgres=# create or replace function foo_trig()
> postgres-# returns trigger as $$
> postgres$# begin
> postgres$# raise notice '%', new;
> postgres$# return null;
> postgres$# end;
> postgres$# $$ language plpgsql;
> CREATE FUNCTION
> postgres=# create trigger xxx after delete on omega for each row
> execute procedure foo_trig();
> CREATE TRIGGER
> postgres=# insert into omega values(20);
> INSERT 0 1
> postgres=# delete from omega;
> ERROR: record "new" is not assigned yet
> DETAIL: The tuple structure of a not-yet-assigned record is indeterminate.
> CONTEXT: PL/pgSQL function "foo_trig" line 3 at RAISE
>
> so current text in documentation is not correct too.

I used your queries to test NEW/OLD on DELETE/INSERT, respectively, and
for statement-level triggers, and you are right that they are
unassigned, not NULL.

The attached patch fixes our documentation for PG 9.3.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

Attachment Content-Type Size
null.diff text/x-diff 1.7 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2012-08-16 00:37:47 Re: ProblemWithCharsOSX
Previous Message Tom Lane 2012-08-16 00:19:49 Re: BUG #7498: Questionable interval parsing when in the form 'n m days'

Browse pgsql-docs by date

  From Date Subject
Next Message Bruce Momjian 2012-08-16 00:38:36 Re: create foreign table
Previous Message Thom Brown 2012-08-15 15:50:54 Re: Foreign server version and type