how to use savepoint and rollback in function

Started by tushar neheteabout 15 years ago3 messagesgeneral
Jump to latest
#1tushar nehete
tpnehete@gmail.com

Hi All,
In Postgresql we can use savepoint and rollback to savepoint in transaction.
But we cannot use savepoint in function.
Currently I am doing migration from Informix to Postgresql 8.4.
In Informix they used Savepoint.
Please advice how to use Savepoint and rollback to savepoint in function.
I know Postgresql has autocommit. But I want to rollback to a particular
savepoint.

Thanks & Regards,
Tushar

#2Alban Hertroys
dalroi@solfertje.student.utwente.nl
In reply to: tushar nehete (#1)
Re: how to use savepoint and rollback in function

On 16 Mar 2011, at 6:25, tushar nehete wrote:

Hi All,
In Postgresql we can use savepoint and rollback to savepoint in transaction.
But we cannot use savepoint in function.
Currently I am doing migration from Informix to Postgresql 8.4.
In Informix they used Savepoint.
Please advice how to use Savepoint and rollback to savepoint in function.
I know Postgresql has autocommit. But I want to rollback to a particular savepoint.

Within functions you can use exceptions with begin/end blocks to get the same behaviour as savepoints and rollbacks.

Alban Hertroys

--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.

!DSPAM:737,4d806b00235886291739995!

#3dhaval jaiswal
dhavallj@hotmail.com
In reply to: tushar nehete (#1)
Re: how to use savepoint and rollback in function

create table mock (id int);
begin;
truncate table mock;
insert into mock values (1),(2);
savepoint A;
insert into mock values (3),(4);
savepoint B;
rollback to savepoint A;
end;

Following link may help you.
http://www.postgresql.org/docs/current/static/sql-rollback-to.html

Date: Wed, 16 Mar 2011 10:55:23 +0530
Subject: [GENERAL] how to use savepoint and rollback in function
From: tpnehete@gmail.com
To: pgsql-general@postgresql.org

Hi All,
In Postgresql we can use savepoint and rollback to savepoint in transaction.
But we cannot use savepoint in function.
Currently I am doing migration from Informix to Postgresql 8.4.
In Informix they used Savepoint.
Please advice how to use Savepoint and rollback to savepoint in function.
I know Postgresql has autocommit. But I want to rollback to a particular savepoint.

Thanks & Regards,
Tushar