Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
Thread:
Lists: pgsql-committerspgsql-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

pgsql-committers by date

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

pgsql-patches by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group