Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id E558B4248 for ; Thu, 22 Mar 2012 14:38:16 -0300 (ADT) Received: from mahout.postgresql.org ([98.129.198.123]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SAlxm-0005lY-Dc for pgsql-bugs@postgresql.org; Thu, 22 Mar 2012 17:38:16 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SAlxY-0000sU-U9 for pgsql-bugs@postgresql.org; Thu, 22 Mar 2012 17:38:01 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1SAlxY-0008UU-A4 for pgsql-bugs@postgresql.org; Thu, 22 Mar 2012 17:38:00 +0000 Date: Thu, 22 Mar 2012 17:38:00 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #6551: PL/pgSQL: GET DIAGNOSTICS not working for first OUT parameter To: pgsql-bugs@postgresql.org From: aburacze@gmail.com X-Pg-Spam-Score: -1.0 (-) X-Archive-Number: 201203/162 X-Sequence-Number: 32723 The following bug has been logged on the website: Bug reference: 6551 Logged by: Adam Buraczewski Email address: aburacze@gmail.com PostgreSQL version: 9.1.3 Operating system: Linux (Fedora 16) Description: = Hi! I have just found strange behaviour of PL/pgSQL in case of using OUT parameters and GET DIAGNOSTICS var =3D ROW_COUNT (PostgreSQL 9.1.3). Here i= s a self-contained example: create table t (c integer); create function p(out x1 integer, out x2 integer, out x3 integer) as $$ begin insert into t values (1); get diagnostics x1 =3D row_count; insert into t values (2); get diagnostics x2 =3D row_count; insert into t values (3); get diagnostics x3 =3D row_count; end; $$ language plpgsql; select * from p(); x1 | x2 | x3 = ----+----+---- | 1 | 1 Why x1 is NULL instead of the value 1? I found a workaround: declare a temporary variable inside the function then assign ROW_COUNT to that variable and then assign temporary variable to the OUT parameter. It works but probably is not the solution one could expect: create function p_workaround(out x1 integer, out x2 integer, out x3 integer) as $$ declare tmpvar integer; begin insert into t values (1); get diagnostics tmpvar =3D row_count; x1 :=3D tmpvar; insert into t values (2); get diagnostics x2 =3D row_count; insert into t values (3); get diagnostics x3 =3D row_count; end; $$ language plpgsql; select * from p_workaround(); x1 | x2 | x3 = ----+----+---- 1 | 1 | 1 Best regards, Adam