Re: #Personal#: Reg: Multiple queries in a transaction

From: Kevin Grittner <kgrittn(at)ymail(dot)com>
To: Medhavi Mahansaria <medhavi(dot)mahansaria(at)tcs(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: #Personal#: Reg: Multiple queries in a transaction
Date: 2015-02-18 16:10:41
Message-ID: 1342988397.596596.1424275841832.JavaMail.yahoo@mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Medhavi Mahansaria <medhavi(dot)mahansaria(at)tcs(dot)com> wrote:

> I need to execute a series of queries
> in a transaction, say Q1, Q2, Q3.
>
> Q1 -> success
> Q2 -> Failed
> Q3 -> Success
>
> My issue is that after Q2 fails all
> the queries that follow give error"ERROR: current transaction
> is aborted, commands ignored until end of transaction block"
>
> I want to move ahead in the transaction
> and execute Q3 also even though Q2 was a failure.
>
> Can you please suggest a way to do so
> in PostgreSQL 9.3.
>
> Is there a way to turn autocommit off?

The server does not support that, but if you're running a script
through psql you should look at using:

\set ON_ERROR_ROLLBACK on

Docs at:

http://www.postgresql.org/docs/9.3/interactive/app-psql.html

If you are not using psql you can use savepoints:

http://www.postgresql.org/docs/8.4/interactive/sql-savepoint.html

ROLLBACK TO SAVEPOINT if the statement fails.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G Johnston 2015-02-18 16:15:22 Re: #Personal#: Reg: Multiple queries in a transaction
Previous Message Adrian Klaver 2015-02-18 16:06:40 Re: Starting new cluster from base backup