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 18:22:32
Message-ID: CAKFQuwZDXdKqTe3w7-da2kLSjR_zk84idZmaa4BCN81BbyQ49Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, Jan 28, 2015 at 10:49 AM, ciamblex [via PostgreSQL] <
ml-node+s1045698n5835817h51(at)n5(dot)nabble(dot)com> wrote:

> Thank you David fot your replay.
>
> I have an other question.
>
> How can i rollback ALL the query when one of these return an error?
>
> My code is like the following:
>
> ------------------------------------
> BEGIN
>
> INSERT INTO table_1 ....
>
> INSERT INTO table_2 ....
>
> INSERT INTO table_3 ....
>
> EXCEPTION WHEN others THEN
> code:=SQLSTATE;
> mess:=SQLERRM;
>
> es:=code||'|'||mess;
>
>
> RETURN es;
>
> END;
> ------------------------------------
>
> In this case when an error occurs the rollback work only on the wrong
> query. The other insert are committed.
>
> ​Based on this statement:

"
When an error is caught by an EXCEPTION clause, the local variables of the
PL/pgSQL function remain as they were when the error occurred, but all
changes to persistent database state within the block are rolled back
​"​

http://www.postgresql.org/docs/9.4/static/plpgsql-control-structures.html

You have either found a bug (documentation or code) or your actual code is
doing something more complex than what you are showing here. If you
provide a self-contained test case that exhibits the behavior you are
observing it will be possible to determine which of those two possibilities
apply.

David J.

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

In response to

Browse pgsql-sql by date

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