Re: Bug in PL/pgSQL GET DIAGNOSTICS?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Michael Paesold" <mpaesold(at)gmx(dot)at>
Cc: "PostgreSQL Hackers Mailing List" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Bug in PL/pgSQL GET DIAGNOSTICS?
Date: 2002-10-14 23:51:17
Message-ID: 9076.1034639477@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Michael Paesold" <mpaesold(at)gmx(dot)at> writes:
> In a PL/pgSQL function I want to insert into a table and get the OID back.
> That usually works with
> GET DIAGNOSTICS last_oid = RESULT_OID;
> right after the insert statement.

> But if the table that I insert to has a rule (or perhaps a trigger?) that
> updates another table, the RESULT_OID after the insert will be 0 (zero).

As of CVS tip, this example produces the results I believe you want:

regression=# SELECT pltestfunc(10);
NOTICE: RESULT_OID: 282229
NOTICE: RESULT_OID: 282230
NOTICE: RESULT_OID: 282231
NOTICE: RESULT_OID: 282232
NOTICE: RESULT_OID: 282233
NOTICE: RESULT_OID: 282234
NOTICE: RESULT_OID: 282235
NOTICE: RESULT_OID: 282236
NOTICE: RESULT_OID: 282237
NOTICE: RESULT_OID: 282238
pltestfunc
------------
t
(1 row)

regression=# SELECT * FROM pltest;
id | t
----+------
1 | test
2 | test
3 | test
4 | test
5 | test
6 | test
7 | test
8 | test
9 | test
10 | test
(10 rows)

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2002-10-14 23:59:24 Re: interesting side effect of autocommit = off
Previous Message Philip Warner 2002-10-14 23:44:44 Re: Let's get 7.3 done