Re: Reg: PL/pgSQL commit and rollback

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Medhavi Mahansaria <medhavi(dot)mahansaria(at)tcs(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Reg: PL/pgSQL commit and rollback
Date: 2015-03-17 14:51:56
Message-ID: 55083F8C.5050802@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 03/17/2015 07:30 AM, Medhavi Mahansaria wrote:
> Yes. I have read this document.
>
> But my issue is that even when it throws and exception I need to
> rollback the changes made by that query and move on to the next block.
>
> Is there any way to accomplish that?

"If no error occurs, this form of block simply executes all the
statements, and then control passes to the next statement after END. But
if an error occurs within the statements, further processing of the
statements is abandoned, and control passes to the EXCEPTION list. The
list is searched for the first condition matching the error that
occurred. If a match is found, the corresponding handler_statements are
executed, and then control passes to the next statement after END. If no
match is found, the error propagates out as though the EXCEPTION clause
were not there at all: the error can be caught by an enclosing block
with EXCEPTION, or if there is none it aborts processing of the function.

I have not looked at your original function in depth, but I am pretty
sure all you have to do is remove the COMMIT and ROLLBACK lines to get
what you want. There are also the RAISE_APPLICATION_ERROR lines to deal
with. Take a look at:

http://www.postgresql.org/docs/9.3/interactive/plpgsql-errors-and-messages.html

Also might want to look at:

http://www.postgresql.org/docs/9.3/interactive/plpgsql-porting.html
--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Israel Brewster 2015-03-17 15:52:42 Re: Group by range in hour of day
Previous Message Alban Hertroys 2015-03-17 14:51:26 Re: Reg: PL/pgSQL commit and rollback