Re: Continue transactions after errors in psql - Mailing list pgsql-patches

From Michael Paesold
Subject Re: Continue transactions after errors in psql
Date
Msg-id 003e01c506f3$0f3665d0$0a01a8c0@zaphod
Whole thread Raw
In response to Re: Continue transactions after errors in psql  ("Greg Sabino Mullane" <greg@turnstep.com>)
Responses Re: Continue transactions after errors in psql
List pgsql-patches
Alvaro Herrera wrote:


>> >Michael Paesold wrote:
>> Alvaro suggested to implement such a function. It is not there yet. I
>> think
>> you would have to access the sub xact stack, but I have not looked into
>> that code for quite some time.
>> http://archives.postgresql.org/pgsql-general/2004-10/msg00370.php
>
> The only problem with this idea is that the function cannot be run when
> the transaction is in aborted state.  Not sure if that is a problem or
> not.  What happens if the user does

I don't think there is a problem. If the transaction is in aborted state, we
only care if the last statement has aborted the transaction. Otherwise we
would not issue our savepoint at all. In that case, i.e. if the last
statement aborted the transaction, we can roll it back anyway, can't we?
There can't be a savepoint on top of us, because that would have failed
right now.
Is my logic wrong?

> SAVEPOINT foo; SLECT 1; ROLLBACK TO foo;
>
> all in one command in psql?
>
> I know psql sends that as three commands, so maybe it's not an issue.

As far as I remember psql splits the three commands, so there would be an
implicit savepoint for each individual statement:

* SAVEPOINT pg_psql_savepoint; -- [1]
SAVEPOINT foo;
* SAVEPOINT pg_psql_savepoint; -- [2]
SLECT 1;
* ROLLBACK TO pg_psql_savepoint; -- [2]
* SAVEPOINT pg_psql_savepoint; -- [3]
ROLLBACK TO foo;
* RELEASE pg_psql_savepoint; -- [3]
* RELEASE pg_psql_savepoint; -- [1], because pg_psql_savepoint is on top of
the stack now again

I hope you get the point. ;-)

Do you think it's better to create a server-side function or handle that in
the client? How hard would it be to implement such a function? And what
should it return? Only the name of the current top savepoint?

Best Regards,
Michael Paesold



pgsql-patches by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Turkish translation updates for 8.0.1
Next
From: Alvaro Herrera
Date:
Subject: Re: Shared dependency patch