Re: Reg: PL/pgSQL commit and rollback

Поиск
Список
Период
Сортировка
От Albe Laurenz
Тема Re: Reg: PL/pgSQL commit and rollback
Дата
Msg-id A737B7A37273E048B164557ADEF4A58B365A7E2B@ntex2010i.host.magwien.gv.at
обсуждение исходный текст
Ответ на Reg: PL/pgSQL commit and rollback  (Medhavi Mahansaria <medhavi.mahansaria@tcs.com>)
Список pgsql-general
Medhavi Mahansaria wrote:
> I am writing a porting a procedure running in oracle to a PL/pgSQL function.
> 
> I need to use commit and rollback in my function.
> 
> I have read that usage of commit and rollback is not possible in PL/pgSQL, however savepoints can be
> used.
> 
> even when i use savepoints and rollback to a savepoint in the exception block I am getting the
> following error
> 
> ERROR:  cannot begin/end transactions in PL/pgSQL
> HINT:  Use a BEGIN block with an EXCEPTION clause instead.

Instead of explicitly using ROLLBACK, you have to code like this:

BEGIN
   INSERT ... -- may cause an error
EXCEPTION
   WHEN OTHERS
   THEN ...
END

If you get into the exception block, PL/pgSQL will implicitly
have rolled back everything that happened between BEGIN and EXCEPTION.

Yours,
Laurenz Albe

В списке pgsql-general по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: Reg: PL/pgSQL commit and rollback
Следующее
От: Medhavi Mahansaria
Дата:
Сообщение: Re: Reg: PL/pgSQL commit and rollback