1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-10 14:22:35 +03:00

Add PL/pgSQL SQLSTATE and SQLERRM support which sets these values on

error.

Pavel Stehule
This commit is contained in:
Bruce Momjian
2005-05-26 00:16:31 +00:00
parent 8c792fe9cb
commit 38af680ad5
6 changed files with 133 additions and 17 deletions

View File

@@ -2380,3 +2380,29 @@ ERROR: control reached end of function without RETURN
CONTEXT: PL/pgSQL function "missing_return_expr"
drop function void_return_expr();
drop function missing_return_expr();
-- test SQLSTATE and SQLERRM
create or replace function trap_exceptions() returns void as $_$
begin
begin
raise exception 'first exception';
exception when others then
raise notice '% %', SQLSTATE, SQLERRM;
end;
raise notice '% %', SQLSTATE, SQLERRM;
begin
raise exception 'last exception';
exception when others then
raise notice '% %', SQLSTATE, SQLERRM;
end;
return;
end; $_$ language plpgsql;
select trap_exceptions();
NOTICE: P0001 first exception
NOTICE: 00000 Sucessful completion
NOTICE: P0001 last exception
trap_exceptions
-----------------
(1 row)
drop function trap_exceptions();

View File

@@ -2018,3 +2018,23 @@ select missing_return_expr();
drop function void_return_expr();
drop function missing_return_expr();
-- test SQLSTATE and SQLERRM
create or replace function trap_exceptions() returns void as $_$
begin
begin
raise exception 'first exception';
exception when others then
raise notice '% %', SQLSTATE, SQLERRM;
end;
raise notice '% %', SQLSTATE, SQLERRM;
begin
raise exception 'last exception';
exception when others then
raise notice '% %', SQLSTATE, SQLERRM;
end;
return;
end; $_$ language plpgsql;
select trap_exceptions();
drop function trap_exceptions();