Обсуждение: Postgresql procedure failing to compile when rollback to savepoint is mentioned
Postgresql procedure failing to compile when rollback to savepoint is mentioned
SQL error:
ERROR: syntax error at or near "TO" LINE 14: ROLLBACK TO SAVEPOINT a; ^
In statement:
CREATE OR REPLACE PROCEDURE transaction_test()
LANGUAGE plpgsql
AS $$
DECLARE
BEGIN
SAVEPOINT a;
insert into public.aocodes(id,cc_id,name,assigned_to,status,entity,created_by)
select 4,4,'101201',8,'Active',1,1;
insert into public.aocodes(id,cc_id,name,assigned_to,status,entity,created_by)
select 4,5,'101201',8,'Active',1,1;
exception
when others then
ROLLBACK TO SAVEPOINT a;
RELEASE SAVEPOINT a;
Commit;
END $$;
Re: Postgresql procedure failing to compile when rollback to savepoint is mentioned
Dear Suport Team,We tried to compile the SP below (statement part) with guidance available onOur aim was to create procedure with transaction rollback on error. We tried to compile the given SP and wanted to run it (which should throw error as the primary key (ID field) has the same value in the second INSERT. On encountering the error, the SP should go to savepoint a without committing the first INSERT.However, we could not handle exceptions with rollback to user-defined SAVEPOINT. The system is throwing error when we try to use ROLLBACK TO SAVEPOINT (mentioned in your manual). Apparently this is a bug as it defies your own example. Please let us know once it is fixed or suggest the alternative at the earliest."SQL error:
ERROR: syntax error at or near "TO" LINE 14: ROLLBACK TO SAVEPOINT a; ^In statement:
CREATE OR REPLACE PROCEDURE transaction_test()
LANGUAGE plpgsql
AS $$
DECLARE
BEGIN
SAVEPOINT a;
insert into public.aocodes(id,cc_id,name,assigned_to,status,entity,created_by)
select 4,4,'101201',8,'Active',1,1;
insert into public.aocodes(id,cc_id,name,assigned_to,status,entity,created_by)
select 4,5,'101201',8,'Active',1,1;
exception
when others then
ROLLBACK TO SAVEPOINT a;
RELEASE SAVEPOINT a;
Commit;
END $$;"
Thanks & RegardsSumit SarkarManaging Consultant0091-86977274430091-8902727443TechTexas Technical Services LLPAN ISO 27001:2013 CompanySuccess is simple. Do what's right, the right way, at the right time. - Arnold H. Glasow