1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-05 07:21:24 +03:00

Add an optional missing_ok argument to SQL function current_setting().

This allows convenient checking for existence of a GUC from SQL, which is
particularly useful when dealing with custom variables.

David Christensen, reviewed by Jeevan Chalke
This commit is contained in:
Tom Lane
2015-07-02 16:40:55 -04:00
parent 7261172430
commit 10fb48d66d
9 changed files with 101 additions and 17 deletions

View File

@ -720,6 +720,37 @@ select myfunc(1), current_setting('work_mem');
2MB | 2MB
(1 row)
-- check current_setting()'s behavior with invalid setting name
select current_setting('nosuch.setting'); -- FAIL
ERROR: unrecognized configuration parameter "nosuch.setting"
select current_setting('nosuch.setting', false); -- FAIL
ERROR: unrecognized configuration parameter "nosuch.setting"
select current_setting('nosuch.setting', true) is null;
?column?
----------
t
(1 row)
-- after this, all three cases should yield 'nada'
set nosuch.setting = 'nada';
select current_setting('nosuch.setting');
current_setting
-----------------
nada
(1 row)
select current_setting('nosuch.setting', false);
current_setting
-----------------
nada
(1 row)
select current_setting('nosuch.setting', true);
current_setting
-----------------
nada
(1 row)
-- Normally, CREATE FUNCTION should complain about invalid values in
-- function SET options; but not if check_function_bodies is off,
-- because that creates ordering hazards for pg_dump

View File

@ -258,6 +258,19 @@ select myfunc(0);
select current_setting('work_mem');
select myfunc(1), current_setting('work_mem');
-- check current_setting()'s behavior with invalid setting name
select current_setting('nosuch.setting'); -- FAIL
select current_setting('nosuch.setting', false); -- FAIL
select current_setting('nosuch.setting', true) is null;
-- after this, all three cases should yield 'nada'
set nosuch.setting = 'nada';
select current_setting('nosuch.setting');
select current_setting('nosuch.setting', false);
select current_setting('nosuch.setting', true);
-- Normally, CREATE FUNCTION should complain about invalid values in
-- function SET options; but not if check_function_bodies is off,
-- because that creates ordering hazards for pg_dump