Re: Transaction Questions

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: rkut(at)intelerad(dot)com
Cc: pgsql-novice(at)postgresql(dot)org, Mathew Kanner <Mathew(dot)Kanner(at)intelerad(dot)com>
Subject: Re: Transaction Questions
Date: 2006-02-24 17:43:10
Message-ID: 4395.1140802990@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Richard Kut <rkut(at)intelerad(dot)com> writes:
> BEGIN
> INSERT
> OR UPDATE
> INSERT
> OR UPDATE
> COMMIT

> Suppose the second INSERT fails with a duplicate key, we cannot do the
> update (or get the previous INSERT) because the ROLLBACK is mandatory.

No it isn't. You say SAVEPOINT, then do the INSERT, then say either
RELEASE SAVEPOINT if the insert succeeded, or ROLLBACK TO SAVEPOINT
if the insert failed. (RELEASE is actually optional here, but might
make things a bit more transparent.) Then you go on with your
transaction. The problem is that you are using transaction-ending
commands where you should be using savepoint-ending commands.

regards, tom lane

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Keith Worthington 2006-02-24 18:42:22 Copy data from one table to another
Previous Message Richard Kut 2006-02-24 17:23:22 Re: Transaction Questions