This article introduces the syntax, parameters, and examples of SET.
Description
The SET command changes run-time configuration parameters. SET only affects the value used by the current session.
If SET (or equivalently SET SESSION) is issued within a transaction that is later aborted, the effects of the SET command disappear when the transaction is rolled back. Once the surrounding transaction is committed, the effects will persist until the end of the session, unless overridden by another SET.
The effects of SET LOCAL last only till the end of the current transaction, whether committed or not. A special case is SET followed by SET LOCAL within a single transaction: the SET LOCAL value will be seen until the end of the transaction, but afterwards (if the transaction is committed) the SET value will take effect.
The effects of SET or SET LOCAL are also canceled by rolling back to a savepoint that is earlier than the command.
If SET LOCAL is used within a function that has a SET option for the same variable, the effects of the SET LOCAL command disappear at function exit; that is, the value in effect when the function was called is restored anyway. This allows SET LOCAL to be used for dynamic or repeated changes of a parameter within a function, while still having the convenience of using the SET option to save and restore the caller's value. However, a regular SET command overrides any surrounding function's SET option; its effects will persist unless rolled back.
Synopsis
SET [ SESSION | LOCAL ] configuration_parameter { TO | = } { value | 'value' | DEFAULT }
SET [ SESSION | LOCAL ] TIME ZONE { timezone | LOCAL | DEFAULT }Parameters
Parameter | Description |
| Specifies in which range the the command takes effect.
|
| The name of a settable run-time parameter. |
| A new value of the parameter. Values can be specified as string constants, identifiers, numbers, or comma-separated lists of these, as appropriate for the particular parameter. |
Usage notes
SCHEMA:SET SCHEMA 'value'is an alias forSET search_path TO value. Only one schema can be specified using this syntax.NAMES:SET NAMES valueis an alias forSET client_encoding TO value.SEED: Sets the internal seed for the random number generator (the functionrandom). Allowed values are floating-point numbers between -1 and 1 inclusive.The seed can also be set by invoking the function
setseed:
SELECT setseed(value);TIME ZONE: SET TIME ZONE value is an alias for SET timezone TO value. The syntax SET TIME ZONE allows special syntax for the time zone specification. Here are examples of valid values:
'PST8PDT': The time zone for Berkeley, California.
'Europe/Rome': The time zone for Italy.
-7: The time zone 7 hours west from UTC (equivalent to PDT). Positive values are east from UTC.
INTERVAL '-08:00' HOUR TO MINUTE: The time zone 8 hours west from UTC (equivalent to PST).
LOCAL DEFAULT: Set the time zone to your local time zone (that is, the server's default value of timezone).
Timezone settings given as numbers or intervals are internally translated to POSIX timezone syntax. For example, after SET TIME ZONE -7, SHOW TIME ZONE would report <-07>+07.
Notes
The function set_config provides equivalent functionality. Also, it is possible to UPDATE the pg_settings system view to perform the equivalent of SET.
Examples
Set the schema search path:
Compatibility issues may occur when you use Data Management (DMS) to configure the search path. In such cases, you can use other clients to execute related statements.
SET search_path TO my_schema, public;Set the time zone:
Set the time zone for Berkeley, California:
SET TIME ZONE 'PST8PDT';Set the time zone for Italy:
SET TIME ZONE 'Europe/Rome';