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:
@ -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
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user