SET
SET — change a run-time parameter
Synopsis
SET [ SESSION | LOCAL ]configuration_parameter{ TO | = } {value| 'value' | DEFAULT }SET [ SESSION | LOCAL ] TIME ZONE {value| 'value' | LOCAL | DEFAULT }
Description
TheSET command changes run-time configuration parameters. Many of the run-time parameters listed inChapter 18 can be changed on-the-fly withSET. (Some parameters can only be changed by superusers and users who have been grantedSET privilege on that parameter. There are also parameters that cannot be changed after server or session start.)SET only affects the value used by the current session.
IfSET (or equivalentlySET SESSION) is issued within a transaction that is later aborted, the effects of theSET 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 anotherSET.
The effects ofSET LOCAL last only till the end of the current transaction, whether committed or not. A special case isSET followed bySET LOCAL within a single transaction: theSET LOCAL value will be seen until the end of the transaction, but afterwards (if the transaction is committed) theSET value will take effect.
The effects ofSET orSET LOCAL are also canceled by rolling back to a savepoint that is earlier than the command.
IfSET LOCAL is used within a function that has aSET option for the same variable (seeCREATE FUNCTION), the effects of theSET LOCAL command disappear at function exit; that is, the value in effect when the function was called is restored anyway. This allowsSET LOCAL to be used for dynamic or repeated changes of a parameter within a function, while still having the convenience of using theSET option to save and restore the caller's value. However, a regularSET command overrides any surrounding function'sSET option; its effects will persist unless rolled back.
Note
InPostgreSQL versions 8.0 through 8.2, the effects of aSET LOCAL would be canceled by releasing an earlier savepoint, or by successful exit from aPL/pgSQL exception block. This behavior has been changed because it was deemed unintuitive.
Parameters
SESSIONSpecifies that the command takes effect for the current session. (This is the default if neither
SESSIONnorLOCALappears.)LOCALSpecifies that the command takes effect for only the current transaction. After
COMMITorROLLBACK, the session-level setting takes effect again. Issuing this outside of a transaction block emits a warning and otherwise has no effect.configuration_parameterName of a settable run-time parameter. Available parameters are documented inChapter 18 and below.
valueNew value of parameter. Values can be specified as string constants, identifiers, numbers, or comma-separated lists of these, as appropriate for the particular parameter.
DEFAULTcan be written to specify resetting the parameter to its default value (that is, whatever value it would have had if noSEThad been executed in the current session).
Besides the configuration parameters documented inChapter 18, there are a few that can only be adjusted using theSET command or that have a special syntax:
SCHEMASET SCHEMA 'is an alias forvalue'SET search_path TO. Only one schema can be specified using this syntax.valueNAMESSET NAMESis an alias forvalueSET client_encoding TO.valueSEEDSets the internal seed for the random number generator (the function
random). 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 ZONESET TIME ZONE 'is an alias forvalue'SET timezone TO '. The syntaxvalue'SET TIME ZONEallows special syntax for the time zone specification. Here are examples of valid values:'America/Los_Angeles'The time zone for Berkeley, California.
'Europe/Rome'The time zone for Italy.
-7The time zone 7 hours west from UTC (equivalent to PDT). Positive values are east from UTC.
INTERVAL '-08:00' HOUR TO MINUTEThe time zone 8 hours west from UTC (equivalent to PST).
LOCALDEFAULTSet 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 ZONEwould report<-07>+07.Time zone abbreviations are not supported by
SET; seeSection 8.5.3 for more information about time zones.
Notes
The functionset_config provides equivalent functionality; seeSection 9.27.1. Also, it is possible to UPDATE thepg_settings system view to perform the equivalent ofSET.
Examples
Set the schema search path:
SET search_path TO my_schema, public;
Set the style of date to traditionalPOSTGRES with“day before month” input convention:
SET datestyle TO postgres, dmy;
Set the time zone for Berkeley, California:
SET TIME ZONE 'America/Los_Angeles';
Set the time zone for Italy:
SET TIME ZONE 'Europe/Rome';
Compatibility
SET TIME ZONE extends syntax defined in the SQL standard. The standard allows only numeric time zone offsets whilePostgres Pro allows more flexible time-zone specifications. All otherSET features arePostgres Pro extensions.