Re: pgsql: Add PL/pgSQL SQLSTATE and SQLERRM support

From: Pavel Stehule <stehule(at)kix(dot)fsv(dot)cvut(dot)cz>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Neil Conway <neilc(at)samurai(dot)com>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, <pgsql-committers(at)postgresql(dot)org>
Subject: Re: pgsql: Add PL/pgSQL SQLSTATE and SQLERRM support
Date: 2005-05-26 16:17:26
Message-ID: Pine.LNX.4.44.0505261759030.3234-100000@kix.fsv.cvut.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-patches

>
> That might be taking the notion of bug-compatibility with PL/SQL
> a bit too far. For that matter, did you check whether Oracle
> actually treats it as a procedure-scope variable? Try having the
> exception block call another function and trap an error inside that.
> Does SQLCODE change in the calling function?
>

good shot. Its more like session (global) variable.

create function foo2
return integer
as
begin
dbms_output.put_line('10: '||SQLCODE||' -> '||SQLERRM);
raise_application_error(-20003, 'Third exception');
end;

change of foo

dbms_output.put_line('3: '||SQLCODE||' -> '||SQLERRM);
--raise_application_error(-20002, 'Second exception');
f := foo2;
exception when others then
dbms_output.put_line('4: '||SQLCODE||' -> '||SQLERRM);
end;

and result:

1: 0 -> ORA-0000: normal, successful completion
2: -20001 -> ORA-20001: First exception
3: -20001 -> ORA-20001: First exception
10: -20001 -> ORA-20001: First exception
4: -20003 -> ORA-20003: Third exception
5: 0 -> ORA-0000: normal, successful completion
6: 0 -> ORA-0000: normal, successful completion

foo2 knows first exception. Is it bug? Maybe. The exception was outside
function, not in function and expected value of SQLCODE is zero.

Pavel

In response to

Browse pgsql-committers by date

  From Date Subject
Next Message Bruce Momjian 2005-05-26 16:44:05 pgsql: Use Abs() macro to replace ? :.
Previous Message Tom Lane 2005-05-26 15:40:51 Re: pgsql: Add PL/pgSQL SQLSTATE and SQLERRM support (Really Oracle behavior)

Browse pgsql-patches by date

  From Date Subject
Next Message Greg Sabino Mullane 2005-05-26 16:58:20 psql backslash consistency
Previous Message Tom Lane 2005-05-26 15:40:51 Re: pgsql: Add PL/pgSQL SQLSTATE and SQLERRM support (Really Oracle behavior)