Re: Surprising behaviour of \set AUTOCOMMIT ON

From: Rahila Syed <rahilasyed90(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Surprising behaviour of \set AUTOCOMMIT ON
Date: 2016-09-01 10:53:33
Message-ID: CAH2L28t5KVHbYgEOguH4WMptbLEd5389teZmsv=77Ow7ppP+QA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Ok. Please find attached a patch which introduces psql error when
autocommit is turned on inside a transaction. It also adds relevant
documentation in psql-ref.sgml. Following is the output.

bash-4.2$ psql -d postgres
psql (10devel)
Type "help" for help.

postgres=# \set AUTOCOMMIT OFF
postgres=# create table test(i int);
CREATE TABLE
postgres=# \set AUTOCOMMIT ON
\set: Cannot set AUTOCOMMIT to ON inside a transaction, either COMMIT or
ROLLBACK and retry
postgres=#

Thank you,
Rahila Syed

On Wed, Aug 17, 2016 at 6:31 PM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:

> On Tue, Aug 16, 2016 at 5:25 PM, Rahila Syed <rahilasyed90(at)gmail(dot)com>
> wrote:
> >>I think I like the option of having psql issue an error. On the
> >>server side, the transaction would still be open, but the user would
> >>receive a psql error message and the autocommit setting would not be
> >>changed. So the user could type COMMIT or ROLLBACK manually and then
> >>retry changing the value of the setting.
> >
> > Throwing psql error comes out to be most accepted outcome on this
> thread. I
> > agree it is safer than guessing user intention.
> >
> > Although according to the default behaviour of psql, error will abort the
> > current transaction and roll back all the previous commands.
>
> A server error would do that, but a psql errror won't.
>
> --
> Robert Haas
> EnterpriseDB: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>

Attachment Content-Type Size
psql_error_on_autocommit.patch application/x-download 1.6 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2016-09-01 11:35:59 Re: PostgreSQL 10 kick-off
Previous Message K S, Sandhya (Nokia - IN/Bangalore) 2016-09-01 10:45:51 Re: Postgres abort found in 9.3.11