From: | Rahila Syed <rahilasyed90(at)gmail(dot)com> |
---|---|
To: | Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com> |
Cc: | Robert Haas <robertmhaas(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Surprising behaviour of \set AUTOCOMMIT ON |
Date: | 2016-09-02 07:42:37 |
Message-ID: | CAH2L28ufhetL31TXNZf2HxgNdnbCU7E66Cb-h9XmumoT_-wiKQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hello,
Thank you for comments.
>Above test not throwing psql error, as you used strcmp(newval,"ON"). You
>should use pg_strcasecmp.
Corrected in the attached.
>Above error coming because in below code block change, you don't have
check for
>command (you should check opt0 for AUTOCOMMIT command)
Corrected in the attached.
>postgres=# BEGIN;
>BEGIN
>postgres=# create table foo ( a int );
>CREATE TABLE
>postgres=# \set AUTOCOMMIT ON
>Don't you think, in above case also we should throw a psql error?
IMO, in this case BEGIN is explicitly specified by user, so I think it is
understood that a commit is required for changes to be effective.
Hence I did not consider this case.
>postgres=# \set AUTOCOMMIT off
>postgres=# create table foo ( a int );
>CREATE TABLE
>postgres=# \set XYZ ON
>\set: Cannot set XYZ to ON inside a transaction, either COMMIT or ROLLBACK
and retry
>May be you would like to move the new code block inside SetVariable(). So
that
>don't need to worry about the validity of the variable names.
I think validating variable names wont be required if we throw error only
if command is \set AUTOCOMMIT.
Validation can happen later as in the existing code.
>Basically if I understand correctly, if we are within transaction and
someone
>tries the set the AUTOCOMMIT ON, it should throw a psql error. Correct me
>if I am missing anything?
Yes the psql_error is thrown when AUTOCOMMIT is turned on inside a
transaction. But only when there is an implicit BEGIN as in following case,
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
Attachment | Content-Type | Size |
---|---|---|
psql_error_on_autocommit_v1.patch | application/x-download | 1.6 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Craig Ringer | 2016-09-02 07:58:33 | Re: Logical decoding slots can go backwards when used from SQL, docs are wrong |
Previous Message | Joel Jacobson | 2016-09-02 07:21:50 | Re: autonomous transactions |