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

From: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to insert in a table the error returns by query
Date: 2015-01-28 19:03:30
Message-ID: CAKFQuwY0NuNk4h5=JBboo8+TU=TpBFEXn43E-GMUi4mhyYiSjw@mail.gmail.com
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] <
ml-node+s1045698n5835837h71(at)n5(dot)nabble(dot)com> 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.

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.

--
View this message in context: http://postgresql.nabble.com/How-to-insert-in-a-table-the-error-returns-by-query-tp5835771p5835838.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Marc Mamin 2015-01-29 18:01:43 Re: How to insert in a table the error returns by query
Previous Message Marc Mamin 2015-01-28 18:52:49 Re: How to insert in a table the error returns by query