I'm trying to understand the exception handling in PL/pgSQL but ...
Case 1:
CREATE OR REPLACE PROCEDURE ins ()
AS $$ DECLARE
i INT;
BEGIN
insert into scott.emp (empno) values (9000);
commit;
i:=1/0;
EXCEPTION WHEN OTHERS THEN
--rollback;
END $$ LANGUAGE plpgsql;
call ins();
I would guess the line is inserted, but it is not
CASE 2:
CREATE OR REPLACE PROCEDURE ins ()
AS $$ DECLARE
i INT;
BEGIN
insert into scott.emp (empno) values (9000);
commit;
--i:=1/0;
EXCEPTION WHEN OTHERS THEN
--rollback;
END $$ LANGUAGE plpgsql;
call ins();
Now, there is no div by zero , but alos no line in the table
Case 3:
CREATE OR REPLACE PROCEDURE ins ()
AS $$ DECLARE
i INT;
BEGIN
insert into scott.emp (empno) values (9000);
commit;
--i:=1/0;
--EXCEPTION WHEN OTHERS THEN
--rollback;
END $$ LANGUAGE plpgsql;
call ins();
Now the line is inserted. It seems that the Problen is my Exception Block, but why?
Thanks in advance. Marco