Re: Surprising behaviour of \set AUTOCOMMIT ON

Поиск
Список
Период
Сортировка
От Rahila Syed
Тема Re: Surprising behaviour of \set AUTOCOMMIT ON
Дата
Msg-id CAH2L28ufhetL31TXNZf2HxgNdnbCU7E66Cb-h9XmumoT_-wiKQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Surprising behaviour of \set AUTOCOMMIT ON  (Rushabh Lathia <rushabh.lathia@gmail.com>)
Ответы Re: Surprising behaviour of \set AUTOCOMMIT ON  (Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>)
Re: Surprising behaviour of \set AUTOCOMMIT ON  (Rushabh Lathia <rushabh.lathia@gmail.com>)
Re: Surprising behaviour of \set AUTOCOMMIT ON  ("Daniel Verite" <daniel@manitou-mail.org>)
Список 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

Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Joel Jacobson
Дата:
Сообщение: Re: autonomous transactions
Следующее
От: Craig Ringer
Дата:
Сообщение: Re: Logical decoding slots can go backwards when used from SQL, docs are wrong