Re: Autocommit off - commits/rollbacks

From: "Vogt, Michael" <Michael(dot)Vogt(at)united-security-providers(dot)ch>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Autocommit off - commits/rollbacks
Date: 2011-03-15 08:22:09
Message-ID: 98D8B015D09D1241A15FD54BA7EAFF150253C2E7@ttsrv02.tetrade.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks alexander

The on_error_rollback setting was exactly the switch I was looking for, thanks. However I tried to set this setting via the jdbc driver (connection object) or jdbc properties, but couldnt find a switch to enable this option.

How can i set this setting from my java app?

Regards and thanks in advance
michael

-----Ursprüngliche Nachricht-----
Von: Alexander Pyhalov [mailto:alp(at)rsu(dot)ru]
Gesendet: Montag, 14. März 2011 17:28
An: Vogt, Michael
Cc: pgsql-general(at)postgresql(dot)org
Betreff: Re: [GENERAL] Autocommit off - commits/rollbacks

Hello.
On 03/14/2011 12:24, Vogt, Michael wrote:
> I have a question, using the autocommit off option in postgres.
>
> As starting position I use a table called xxx.configuration using a
> unique id constraint.
>
> Why does postgres rollback the whole transaction after an error? I
> compared the behavior with oracle/hsql - those dbms commit whats
> possible. To illustrate my question, here are some examples:
....
AFAIK, sqlplus uses savepoints behind the scene. So, you can do something like this:

> create table t1 (i int unique);
CREATE TABLE
> begin;
BEGIN
*> insert into t1 values(1);
INSERT 0 1
*> savepoint s1;
SAVEPOINT
*> insert into t1 values(2);
INSERT 0 1
*> savepoint s2;
SAVEPOINT
*> insert into t1 values(2);
ERROR: duplicate key value violates unique constraint "t1_i_key"
!> ROLLBACK TO SAVEPOINT s2;
ROLLBACK
*> commit;
COMMIT

Or, you can just do:
> \set ON_ERROR_ROLLBACK on

--
Best regards,
Alexander Pyhalov,
system administrator of Computer Center of Southern Federal University

In response to

Browse pgsql-general by date

  From Date Subject
Next Message hubert depesz lubaczewski 2011-03-15 10:32:27 Re: Huge spikes in number of connections doing "PARSE"
Previous Message John R Pierce 2011-03-15 08:12:02 Re: base backup and tar problems with disappearing files.