Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t2B3a-002Ldy-CM for pgsql-general@arkaria.postgresql.org; Sat, 19 Oct 2024 15:07:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t2B3X-003zFT-Bn for pgsql-general@arkaria.postgresql.org; Sat, 19 Oct 2024 15:07:51 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t2B3X-003zFH-0w for pgsql-general@lists.postgresql.org; Sat, 19 Oct 2024 15:07:51 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t2B3U-001iHE-Dz for pgsql-general@lists.postgresql.org; Sat, 19 Oct 2024 15:07:50 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 49JF7kag1095765; Sat, 19 Oct 2024 11:07:46 -0400 From: Tom Lane To: Marcelo Zabani cc: "pgsql-generallists.postgresql.org" Subject: Re: RESET, NULL and empty-string valued settings and transaction isolation In-reply-to: References: Comments: In-reply-to Marcelo Zabani message dated "Sat, 19 Oct 2024 11:07:06 -0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1095763.1729350466.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 19 Oct 2024 11:07:46 -0400 Message-ID: <1095764.1729350466@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Marcelo Zabani writes: > 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" This is, I guess, strictly true only for built-in settings. Custom settings act a little differently in that they don't exist at all before you assign to them. Thus > $ psql > =3D> select current_setting('my.test', true) is null; -- true my.test doesn't exist here. current_setting(..., true) returns NULL instead of throwing an error, although SHOW reacts differently: regression=3D# show my.test; ERROR: unrecognized configuration parameter "my.test" > =3D> set my.test =3D 'abc'; > =3D> reset my.test; Now it does exist, but its reset value is an empty string. > =3D> select current_setting('my.test', true) is null; -- false > =3D> select current_setting('my.test', true)=3D''; -- 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 particular= ly > confusing and basically requires usage of nullif(.., '') or other explic= it > checks around every current_setting call-site in practice. [ shrug... ] This whole area is an undocumented, unsupported abuse of a behavior that's only meant to support GUCs defined by loadable extensions. (To wit, allowing postgresql.conf to set values for GUCs that aren't loaded yet.) Without a way to declare a GUC's type, reset value, etc, there's no way to have custom GUCs act really consistently with built-in ones. Pavel Stehule has spent years pushing forward a patch to invent a better-thought-out implementation of custom session variables [1]. Every time I look at it, I come away with the feeling that it's a giant patch with a much smaller patch struggling to get out. But certainly the area needs some nontrivial thought, and I'm not sure that extending the GUC mechanism is a better answer. regards, tom lane [1] https://www.postgresql.org/message-id/flat/CAFj8pRD053CY_N4%3D6SvPe7ke= 6xPbh%3DK50LUAOwjC3jm8Me9Obg%40mail.gmail.com