Thread: Bug in Configuration Setting Functions after a Commit
Hello:
I'm enthusiastic about the PostgreSQL project and this is my first bug report. Please apologize if I'm on the wrong channel.
The bug is the following: when I set a custom variable using the configuration settings functions within a transaction, after I commit the transaction, instead of the variable becoming null, it becomes an empty string.
How to reproduce:
SELECT current_setting('custom.user_id', true)::INTEGER; -- NULL
BEGIN;
SELECT set_config('custom.user_id', '2', true);
SELECT current_setting('custom.user_id', true)::INTEGER; -- 2
END;
SELECT set_config('custom.user_id', '2', true);
SELECT current_setting('custom.user_id', true)::INTEGER; -- 2
END;
SELECT current_setting('custom.user_id', true)::INTEGER; -- Empty string instead of null
PostgreSQL version: PostgreSQL 15.10 (Debian 15.10-0+deb12u1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
On Mon, Feb 24, 2025 at 11:32 AM João felipe Chiarelli Bourscheid <joao.felipe.c.b@gmail.com> wrote:
The bug is the following: when I set a custom variable using the configuration settings functions within a transaction, after I commit the transaction, instead of the variable becoming null, it becomes an empty string.
Yes, this is working as designed. The variable will never take on the null value, and the system won't forget that it exists once created, so the default value of empty string is restored when the transaction ends.
There is some work-in-progress to clarify this in the documentation.
David J.
Re: Bug in Configuration Setting Functions after a Commit
From
João felipe Chiarelli Bourscheid
Date:
Thanks, is there a way that I can help contrinuting to writing this into the documentation? Should I refer to pgsql-docs@lists.postgresql.org ?
Em seg., 24 de fev. de 2025 15:38, David G. Johnston <david.g.johnston@gmail.com> escreveu:
On Mon, Feb 24, 2025 at 11:32 AM João felipe Chiarelli Bourscheid <joao.felipe.c.b@gmail.com> wrote:The bug is the following: when I set a custom variable using the configuration settings functions within a transaction, after I commit the transaction, instead of the variable becoming null, it becomes an empty string.Yes, this is working as designed. The variable will never take on the null value, and the system won't forget that it exists once created, so the default value of empty string is restored when the transaction ends.There is some work-in-progress to clarify this in the documentation.David J.
On Mon, Feb 24, 2025 at 11:49 AM João felipe Chiarelli Bourscheid <joao.felipe.c.b@gmail.com> wrote:
Thanks, is there a way that I can help contrinuting to writing this into the documentation? Should I refer to pgsql-docs@lists.postgresql.org ?
I have targeted commitfest entry for this issue here:
And a larger rework regarding NULL here that covers this topic briefly since it is a bit unintuitive that settings may not take on a null value; while current_setting can return NULL as an error-substitute sentinel value.
Reviewing them would be very helpful.
David J.