current_setting()

A function returning the current value of a configuration parameter

current_setting() is a system function returning the current value of a configuration parameter and certain other values.

current_setting() was added in PostgreSQL 7.3.

Usage

current_setting ( setting_name text [, missing_ok boolean ] ) → text

Similar to the SHOW command, current_setting() returns the current value of a configuration parameter (and certain other parameters). However in contrast to SHOW, current_setting() is a normal function and can be combined with other SQL elements. Additionally, it can display custom variables, and can optionally be executed without returning an error if the specified configuration parameter does not exist.

Like SHOW, current_setting() can also display whether the current user is a superuser via the pseudo-parameter is_superuser.

The system catalog view pg_settings can also be used to retrieve information about the current value of configuration parameters.

Change history

Examples

Retrieve a normal configuration parameter:

postgres=# SELECT current_setting('port');
 current_setting 
-----------------
 5432
(1 row)

Attempt to retrieve a configuration parameter which does not exist:

postgres=# SELECT current_setting('foo');
ERROR:  unrecognized configuration parameter "foo"

Safely attempt to retrieve a configuration parameter which might not exist (PostgreSQL 9.6 and later):

postgres=# SELECT current_setting('foo', true);
 current_setting 
-----------------
 
(1 row)

Display whether the current user is a superuser:

postgres=# SELECT current_setting('is_superuser');
 current_setting 
-----------------
 on
(1 row)

Categories

Configuration, System function

See also

pg_settings, SHOW, set_config()