SET(7)
π NAME π
okay bestie, welcome to SET(7) β this is the PostgreSQL 17.11 documentation page for the SET command, and itβs literally about changing a run-time parameter. π«Ά
SET β change a run-time parameter. thatβs the name. thatβs the whole assignment. π
β¨ SYNOPSIS β¨
SET [ SESSION | LOCAL ] configuration_parameter { TO | = } { value | 'value' | DEFAULT }
SET [ SESSION | LOCAL ] TIME ZONE { value | 'value' | LOCAL | DEFAULT }
two forms, pick your fighter π
πΈ DESCRIPTION πΈ
the SET command changes run-time configuration parameters. many of the run-time parameters listed in Chapter 19 can be changed on-the-fly with SET. (some parameters can only be changed by superusers and users who have been granted SET 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. π
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 (see CREATE FUNCTION (CREATE_FUNCTION(7))), 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. π
note, bestie: in PostgreSQL versions 8.0 through 8.2, the effects of a SET LOCAL would be canceled by releasing an earlier savepoint, or by successful exit from a PL/pgSQL exception block. this behavior has been changed because it was deemed unintuitive. π
π PARAMETERS π
hereβs the cast, bestie π
SESSIONβ specifies that the command takes effect for the current session. (this is the default if neitherSESSIONnorLOCALappears.) πLOCALβ specifies that the command takes effect for only the current transaction. afterCOMMITorROLLBACK, the session-level setting takes effect again. issuing this outside of a transaction block emits a warning and otherwise has no effect. β οΈconfiguration_parameterβ name of a settable run-time parameter. available parameters are documented in Chapter 19 and below. π¦valueβ 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.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 in Chapter 19, there are a few that can only be adjusted using the SET command or that have a special syntax:
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-1and1inclusive. the seed can also be set by invoking the functionsetseed:
SELECT setseed(value);
TIME ZONEβSET TIME ZONE 'value'is an alias forSET timezone TO 'value'. the syntaxSET 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. π-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 oftimezone). π
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. π
time zone abbreviations are not supported by SET; see Section 8.5.3 for more information about time zones. π«
π NOTES π
the function set_config provides equivalent functionality; see Section 9.28.1. also, it is possible to UPDATE the pg_settings system view to perform the equivalent of SET. π₯
π EXAMPLES π
set the schema search path:
SET search_path TO my_schema, public;
set the style of date to traditional POSTGRES 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 while PostgreSQL allows more flexible time-zone specifications. all other SET features are PostgreSQL extensions. π
π SEE ALSO π
okay bye bestie π β this SET(7) page is from PostgreSQL 17.11, dated 2026, and itβs giving iconic documentation energy. slay. β¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms