Re: Transaction Questions - Mailing list pgsql-novice

From Tom Lane
Subject Re: Transaction Questions
Date
Msg-id 4395.1140802990@sss.pgh.pa.us
Whole thread Raw
In response to Re: Transaction Questions  (Richard Kut <rkut@intelerad.com>)
Responses Re: Transaction Questions
List pgsql-novice
Richard Kut <rkut@intelerad.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

pgsql-novice by date:

Previous
From: Richard Kut
Date:
Subject: Re: Transaction Questions
Next
From: "Keith Worthington"
Date:
Subject: Copy data from one table to another