Skip site navigation (1) Skip section navigation (2)

Re: Continue transactions after errors in psql

From: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
To: Greg Sabino Mullane <greg(at)turnstep(dot)com>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: Continue transactions after errors in psql
Date: 2005-01-28 06:48:44
Message-ID: 200501280148.44060.xzilla@users.sourceforge.net (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-patches
On Tuesday 25 January 2005 22:07, Greg Sabino Mullane wrote:
> Attached is a patch that takes advantage of savepoints to enable
> transactions to continue even after errors in psql. The name of it
> is \reseterror, and it is off by default. It's backwards compatible,
> and allows things like this to work on 8.0 and up servers:
>
> \reseterror
> BEGIN;
> DELETE FROM foobar;
> INSERT INTO foobar(a) VALUES(1);
> ISNER INTO foobar(a) VALUES(2);
> INSERT INTO foobar(a) VALUES(3);
> COMMIT;
>
> Doing a SELECT(a) FROM foobar will show two values, 1 and 3. This
> is a great help for those of us that tend to type typos into our
> psql session, and end up cursing as we have to restart our current
> transaction. :)

I've been testing this patch and found the following bug:
test=# \reseterror
Reset error is on.
test=# begin;
BEGIN
test=# select * from t;
 c
---
 1
(1 row)
test=# delete from t;
DELETE 1
test=# select * from tt;
ERROR:  relation "tt" does not exist
ERROR:  relation "tt" does not exist
test=# select * from t;
 c
---
(0 rows)
test=# commit;
COMMIT
ERROR:  RELEASE SAVEPOINT may only be used in transaction blocks
ERROR:  RELEASE SAVEPOINT may only be used in transaction blocks


I've attached a revised patch which fixes the problem, however I'm sure there 
is a better way.  Thanks to Neil for putting up with me on irc :-)

-- 
Robert Treat
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL

Attachment: reseterror2.patch
Description: text/x-diff (6.1 KB)

In response to

Responses

pgsql-hackers by date

Next:From: Sibtay AbbasDate: 2005-01-28 07:32:22
Subject: storage of compiled functions
Previous:From: David ParkerDate: 2005-01-28 02:40:25
Subject: Re: Strange issue with initdb on 8.0 and Solaris automounts

pgsql-patches by date

Next:From: Christopher Kings-LynneDate: 2005-01-28 09:46:13
Subject: Re: Continue transactions after errors in psql
Previous:From: Ed L.Date: 2005-01-28 06:31:17
Subject: Re: dbsize patch

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group