After setting the configuration parameter with set_config() I can read it with current_setting(). But if exception ocured and I try to read value within the exception block it is undefined.
do $$declare
l_ctx_prm text := 'some_value';
l_dummy numeric;
begin
raise notice 'test before set_config: [utl_log.test_ctx=%]', current_setting('utl_log.test_ctx', true);
perform set_config('utl_log.test_ctx', l_ctx_prm, false);
raise notice 'test after set_config: [utl_log.test_ctx=%]', current_setting('utl_log.test_ctx', true);
l_dummy := 1/0; -- raise exception
exception when others then
raise notice 'test in exception block: [utl_log.test_ctx=%]', current_setting('utl_log.test_ctx', true);
end$$;
The result is
test before set_config: [utl_log.test_ctx=<NULL>]
test after set_config: [utl_log.test_ctx=some_value]
test in exception block: [utl_log.test_ctx=]
Can someone explain this behavior?