Bug in psql (on_error_rollback)

From: "Michael Paesold" <mpaesold(at)gmx(dot)at>
To: <pgsql-patches(at)postgresql(dot)org>
Subject: Bug in psql (on_error_rollback)
Date: 2005-09-16 15:17:49
Message-ID: 00c001c5bad1$ccbbfb50$0f01a8c0@zaphod
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

There is a bug in psql for the new ON_ERROR_ROLLBACK feature. In AUTOCOMMIT
off mode it does not work correctly for the first statement.

This is how it works usually:
====================================
postgres=# \set AUTOCOMMIT off
postgres=# \set ON_ERROR_ROLLBACK interactive
postgres=# SELECT 1;
?column?
----------
1
(1 row)

postgres=# SELECT a;
ERROR: column "a" does not exist
postgres=# SELECT 1;
?column?
----------
1
(1 row)

postgres=# BEGIN;
WARNING: there is already a transaction in progress
BEGIN
postgres=# ROLLBACK;
ROLLBACK
====================================

For the first statement in a transaction after the implicit BEGIN it does
not work:
====================================
postgres=# ROLLBACK;
ROLLBACK
postgres=#
postgres=# SELECT a;
ERROR: column "a" does not exist
postgres=# SELECT 1;
ERROR: current transaction is aborted, commands ignored until end of
transaction block
====================================

With the attaced patch it works correctly even for the first statement.
====================================
postgres=# \set AUTOCOMMIT off
postgres=# \set ON_ERROR_ROLLBACK interactive
postgres=# SELECT a;
ERROR: column "a" does not exist
postgres=# SELECT 1;
?column?
----------
1
(1 row)

postgres=# BEGIN;
WARNING: there is already a transaction in progress
BEGIN
postgres=# ABORT;
ROLLBACK
====================================

Please check the patch and apply to CVS tip.
I think it would be good to add regression tests for AUTOCOMMIT and
ON_ERROR_ROLLBACK and possibly others. There are currently no regression
tests specifically for psql features, but since the regression tests are
executed via psql, there would be no problem in creating a set of such
tests, right?. I could write some.

Best Regards,
Michael Paesold

Attachment Content-Type Size
psql.patch application/octet-stream 973 bytes

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2005-09-16 15:18:46 Re: statement logging / extended query protocol issues
Previous Message Bruce Momjian 2005-09-16 15:15:30 Re: statement logging / extended query protocol issues