RESET, NULL and empty-string valued settings and transaction isolation

From: Marcelo Zabani <mzabani(at)gmail(dot)com>
To: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: RESET, NULL and empty-string valued settings and transaction isolation
Date: 2024-10-19 14:07:06
Message-ID: CACgY3QbXpCBpM9ShSo2-VM9x=5GiXJeY-4hqhCXa8bkEGuXGvw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi, according to the docs, RESET sets the value of a setting to
"The default value is defined as the value that the parameter would have
had, if no SET had ever been issued for it in the current session"

Which confuses me given that the value starts being NULL in the session and
then turns into an empty string:
$ psql
=> select current_setting('my.test', true) is null; -- true
=> set my.test = 'abc';
=> reset my.test;
=> select current_setting('my.test', true) is null; -- false
=> select current_setting('my.test', true)=''; -- true

A similar effect happens with transactions and SET LOCAL:
=> begin;
=*> set local my.test='abc';
=*> rollback; -- commit works too
=> select current_setting('my.test', true) = ''; -- true

Is this expected? I thought even if I misunderstand the docs, the effect
isn't very nice because SQL like
current_setting('my.some_boolean_setting')::boolean will fail after a
transaction with SET LOCAL sets it, a side-effect that can be particularly
confusing and basically requires usage of nullif(.., '') or other explicit
checks around every current_setting call-site in practice.

Thanks in advance,
Marcelo.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2024-10-19 15:03:33 Re: RESET, NULL and empty-string valued settings and transaction isolation
Previous Message Venkata Nori 2024-10-19 07:23:58 RE: Postgres installation is failing in mac