Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T1nzT-00089n-Vq for pgsql-docs@postgresql.org; Thu, 16 Aug 2012 00:31:12 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T1nzQ-000598-Dp for pgsql-docs@postgresql.org; Thu, 16 Aug 2012 00:31:11 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1T1nzP-0002xP-JY; Wed, 15 Aug 2012 20:31:07 -0400 Date: Wed, 15 Aug 2012 20:31:07 -0400 From: Bruce Momjian To: Pavel Stehule Cc: Josh Kupershmidt , pgsql-docs Subject: Re: [BUGS] documentation bug - behave of NEW a OLD in plpgsql's triggers Message-ID: <20120816003107.GA8353@momjian.us> References: <201109070254.p872sd418092@momjian.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="pf9I7BMVVzbSWLtt" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201208/24 X-Sequence-Number: 7417 --pf9I7BMVVzbSWLtt Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Wed, Sep 7, 2011 at 03:40:19PM +0200, Pavel Stehule wrote: > 2011/9/7 Josh Kupershmidt : > > On Tue, Sep 6, 2011 at 10:54 PM, Bruce Momjian 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 http://momjian.us EnterpriseDB http://enterprisedb.com + It's impossible for everything to be true. + --pf9I7BMVVzbSWLtt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="null.diff" diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml new file mode 100644 index ab40845..07fba57 *** a/doc/src/sgml/plpgsql.sgml --- b/doc/src/sgml/plpgsql.sgml *************** RAISE unique_violation USING MESSAGE = ' *** 3403,3409 **** Data type RECORD; variable holding the new database row for INSERT/UPDATE operations in row-level ! triggers. This variable is NULL in statement-level triggers and for DELETE operations. --- 3403,3409 ---- Data type RECORD; variable holding the new database row for INSERT/UPDATE operations in row-level ! triggers. This variable is unassigned in statement-level triggers and for DELETE operations. *************** RAISE unique_violation USING MESSAGE = ' *** 3415,3421 **** Data type RECORD; variable holding the old database row for UPDATE/DELETE operations in row-level ! triggers. This variable is NULL in statement-level triggers and for INSERT operations. --- 3415,3421 ---- Data type RECORD; variable holding the old database row for UPDATE/DELETE operations in row-level ! triggers. This variable is unassigned in statement-level triggers and for INSERT operations. --pf9I7BMVVzbSWLtt--