Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP

From: Christophe Pettus <xof(at)thebuild(dot)com>
To: Ravi Krishna <s_ravikrishna(at)aol(dot)com>
Cc: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP
Date: 2022-10-18 21:31:56
Message-ID: 80B77102-84D3-4AD8-B138-1C0C3341855B@thebuild.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> On Oct 18, 2022, at 14:29, Ravi Krishna <s_ravikrishna(at)aol(dot)com> wrote:
>
> > You can commit in a loop, but not in BEGIN / END block that has an exception handler:
> > that creates a subtransaction for the duration of the BEGIN / END.
>
> The reason I have to deal with error exception is that I want to ignore failure on a table and move on to next table.

Rather than have a loop inside the BEGIN / END, you could put the BEGIN EXCEPTION END inside the loop, catch the error, store the important parts of the exception in a variable, and then do the COMMIT after the END statement but before the next iteration of the loop. A bit messier, but it gets the job done.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2022-10-18 21:33:37 Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP
Previous Message Ravi Krishna 2022-10-18 21:29:11 Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP