pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: aburacze@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #6551: PL/pgSQL: GET DIAGNOSTICS not working for first OUT parameter
Date: Thu, 22 Mar 2012 17:38:00 +0000
Message-ID: <E1SAlxY-0008UU-A4@wrigleys.postgresql.org> (raw)

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 = ROW_COUNT (PostgreSQL 9.1.3). Here is 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 = row_count;
    insert into t values (2);
    get diagnostics x2 = row_count;
    insert into t values (3);
    get diagnostics x3 = 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 = row_count;
    x1 := tmpvar;
    insert into t values (2);
    get diagnostics x2 = row_count;
    insert into t values (3);
    get diagnostics x3 = row_count;
end;
$$ language plpgsql;

select * from p_workaround();

 x1 | x2 | x3 
----+----+----
  1 |  1 |  1

Best regards,
Adam




view thread (4+ messages)  latest in thread

Message-ID: <E1SAlxY-0008UU-A4@wrigleys.postgresql.org>
Permalink:  ../E1SAlxY-0008UU-A4@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/E1SAlxY-0008UU-A4@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: aburacze@gmail.com
  Subject: Re: BUG #6551: PL/pgSQL: GET DIAGNOSTICS not working for first OUT parameter
  In-Reply-To: <E1SAlxY-0008UU-A4@wrigleys.postgresql.org>
  References: <E1SAlxY-0008UU-A4@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox