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

Implementation of SQLCODE and SQLERRM variables for PL/pgSQL

From: Pavel Stehule <stehule(at)kix(dot)fsv(dot)cvut(dot)cz>
To: Ali Baba <idofyear(at)yahoo(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, <pgsql-patches(at)postgresql(dot)org>
Subject: Implementation of SQLCODE and SQLERRM variables for PL/pgSQL
Date: 2005-03-06 19:24:38
Message-ID: Pine.LNX.4.44.0503062003220.32436-600000@kix.fsv.cvut.cz (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-patches
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

Attachment: gram.y.diff
Description: text/plain (1.3 KB)
Attachment: pl_exec.c.diff
Description: text/plain (1.0 KB)
Attachment: plpgsql.h.diff
Description: text/plain (66 bytes)
Attachment: test.out
Description: text/plain (187 bytes)
Attachment: test.sql
Description: text/plain (538 bytes)

In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2005-03-06 20:05:05
Subject: Re: Implementation of SQLCODE and SQLERRM variables for PL/pgSQL
Previous:From: Tom LaneDate: 2005-03-06 19:14:47
Subject: Speeding up tupledesc copying

pgsql-patches by date

Next:From: Tom LaneDate: 2005-03-06 19:52:08
Subject: Re: Cleaning up unreferenced table files
Previous:From: Neil ConwayDate: 2005-03-06 08:49:05
Subject: Re: Display Pg buffer cache (WIP)

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