Implementation of SQLCODE and SQLERRM variables for PL/pgSQL - Mailing list pgsql-hackers

From Pavel Stehule
Subject Implementation of SQLCODE and SQLERRM variables for PL/pgSQL
Date
Msg-id Pine.LNX.4.44.0503062003220.32436-600000@kix.fsv.cvut.cz
Whole thread Raw
In response to Re: Exception ERROR Code  (Pavel Stehule <stehule@kix.fsv.cvut.cz>)
Responses Re: Implementation of SQLCODE and SQLERRM variables for PL/pgSQL  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hello

  This is my second patch, than please will be tolerant :-). For one my
project I miss information about exception when I use EXCEPTION WITH
OTHERS THEN. I found two Oracle's varaibles SQLCODE and SQLERRM which
carry this information. With patch you can:


--
-- Test of built variables SQLERRM and SQLCODE
--

create or replace function trap_exceptions() returns void as $_$
begin
  begin
    raise exception 'first exception';
  exception when others then
    raise notice '% %', SQLCODE, SQLERRM;
  end;
  raise notice '% %', SQLCODE, SQLERRM;
  begin
    raise exception 'last exception';
  exception when others then
    raise notice '% %', SQLCODE, SQLERRM;
  end;
  return;
end; $_$ language plpgsql;

select trap_exceptions();

drop function trap_exceptions();

CREATE FUNCTION
NOTICE:  P0001 first exception
NOTICE:  000000 Sucessful completion
NOTICE:  P0001 last exception
 trap_exceptions
-----------------

(1 row)

DROP FUNCTION


Regards,
Pavel Stehule

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Speeding up tupledesc copying
Next
From: Tom Lane
Date:
Subject: Re: Implementation of SQLCODE and SQLERRM variables for PL/pgSQL