Project: YugabyteDB (App Definition and Development / Database)
File: cmd_set.md

title: SET statement [YSQL] headerTitle: SET linkTitle: SET description: Use the SET statement to update a run-time control parameter. menu: v2.18: identifier: cmd_set parent: statements type: docs Use the `SET` statement to change the value of a run-time parameter. {{%ebnf%}} set {{%/ebnf%}} The parameter values that you set with this statement apply just in the scope of a single session and for no longer than the session's duration. It's also possible to set the default values for such parameters at the level of the entire cluster or at the level of a particular database. For example: ```plpgsql alter database demo set timezone = 'America/Los_Angeles'; ``` See . Specify that the command affects only the current session. Specify that the command affects only the current transaction. After `COMMIT` or `ROLLBACK`, the run-time parameter takes effect again. Specify the name of a mutable run-time parameter. You can inspect the current value of a run-time parameter with the currentsetting()_ built-in function, for example: ```plpgsql select currentsetting('searchpath'); ``` The term of art setting is used as a convenient shorthand for run-time parameter. Many run-time parameters are system-defined. A system-defined run-time parameter is spelled using only latin letters and underscores. And, in any particular PostgreSQL version, the list of system-defined run-time parameters is fixed. The `show ...` SQL statement is a shorthand for select currentsetting(...)_, for example: ```plpgsql show search_path; ``` The `show` statement has a special variant `show all`, not available when you use select currentsetting(...), that lists the current value of every system-defined run-time parameter. (An alternative way to see this list, with some useful accompanying information for each setting, is to query the pgsettings catalog view.) Specify the value of parameter. You can also create a user-defined run-time parameter, on the fly, by spelling it suitably. The duration of a user-defined run-time parameter never exceeds that of the session. The spelling must include a period. And, as long as you double-quote in in the `set` statement, it can contain any combination of arbitrary characters. Try this: ```plpgsql set min.vrelse17 = 'stue'; set "MIN.VRELSE17@" = 'kjkken'; set "^." = ''; select current_setting('min.vrelse17') as s1, current_setting('MIN.VRELSE17@') as s2, current_setting('^.') as s3; ``` This is the result: ```output s1 | s2 | s3 ++ stue | kjkken | ``` Notice that `show all` and querying pgsettings_ never lists user-defined run-time parameters. Try this test: ```plpgsql set searchpath = pgcatalog, pg_temp; start transaction; set searchpath = someschema, pgcatalog, pgtemp; set my.value = 'something'; select currentsetting('searchpath'); select current_setting('my.value'); rollback; select currentsetting('searchpath'); select '>'||current_setting('my.value')||'<'; ``` The test outputs this: ```output someschema, pgcatalog, pg_temp ``` followed by this: ```output something ``` when the transaction is ongoing and this: ```output pgcatalog, pgtemp ``` followed by this: ```output >< ``` following the `rollback`. This shows that the user-defined run-time parameter has been created for the duration of the session and that its value following the `rollback` is the empty string.