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;
>postgres=# create table foo ( a int );
>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 );
>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
>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
>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);
postgres=# \set AUTOCOMMIT ON
\set: Cannot set AUTOCOMMIT to ON inside a transaction, either COMMIT or
ROLLBACK and retry

Thank you,
Rahila Syed

Attachment: psql_error_on_autocommit_v1.patch
Description: application/download

Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:

Reply via email to