Re: How to insert in a table the error returns by query

From: Marc Mamin <M(dot)Mamin(at)intershop(dot)de>
To: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>, "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: How to insert in a table the error returns by query
Date: 2015-01-29 18:01:43
Message-ID: B6F6FD62F2624C4C9916AC0175D56D8828B588BB@jenmbs01.ad.intershop.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


>On Wed, Jan 28, 2015 at 11:53 AM, Marc Mamin-2 [via PostgreSQL] <[hidden email]> wrote:
>
>
> >In this case when an error occurs the rollback work only on the wrong query. The other insert are committed.
>
>
> The rollback only takes place on the errored statement, because you are catching the exception.
> In order to ensure a complete rollback of your transaction (which may have started outside of your function),
> you'll need to rethrow an error after your exception handling.
>
>
> The 9.4 documentation is in direct conflict with this statement...all persistent updates inside the associated BEGIN/END block should be rolled back.

You are right, and a quick test with 9.3.5 is consistent with the doc.
regards,

Marc Mamin

>
>Transactions MUST start "outside your function" by definition. By not re-throwing the exception any outer block (i.e., the one calling the function) would still end up intact but every statement inside of the function should rollback unless separate blocks are created to isolate the different statements.
>
>David J.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Nii Gii 2015-02-10 11:39:28 Implementing incremental client updates
Previous Message David G Johnston 2015-01-28 19:03:30 Re: How to insert in a table the error returns by query