SET(7)

πŸ“¦ version 16.15, in opensuse-leap 16.0

πŸ’… SET(7) β€” the PostgreSQL 16.15 glow-up guide ✨

okay so bestie, pull up a chair, because we're talking about SET β€” the little command that lets you change run-time parameters on the fly, and honestly? she's iconic. πŸ‘‘


🌸 NAME 🌸

SET β€” change a run-time parameter. that's it. that's the whole vibe. πŸ’«


πŸŽ€ SYNOPSIS πŸŽ€

SET [ SESSION | LOCAL ] configuration_parameter { TO | = } { value | 'value' | DEFAULT }
SET [ SESSION | LOCAL ] TIME ZONE { value | 'value' | LOCAL | DEFAULT }

two whole forms, both serving. periodt. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so the SET command changes run-time configuration parameters, and like β€” so many of the run-time parameters listed in Chapter 20 can be changed on-the-fly with SET. it's giving flexibility, it's giving main character energy. 🌈

highkey important caveat though, no cap: some parameters can only be changed by superusers and users who have been granted SET privilege on that parameter. and there are also parameters that cannot be changed after server or session start. so like, check your permissions first, bestie. πŸ’€

and remember: SET only affects the value used by the current session. your neighbor's session is unbothered, living her own life. πŸ’œ

here's the transaction tea, and it's kinda a lot so stay with me:

  • 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. poof. gone. πŸ™ˆ
  • once the surrounding transaction is committed, the effects will persist until the end of the session β€” unless overridden by another SET. literally the setting that stays with you. πŸ’–
  • the effects of SET LOCAL last only till the end of the current transaction, whether committed or not. short but fierce. πŸŽ€
  • special case alert 🚨: 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 plot twist of it all. ✨
  • the effects of SET or SET LOCAL are also canceled by rolling back to a savepoint that is earlier than the command. time travel, but make it SQL. ⭐

now, function behavior β€” yes this is still happening, drink some water πŸ“:

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. so it's giving "what happens in the function stays in the function." πŸ™ˆ 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. best of both worlds honestly. 🫢

however β€” and I need you to hear this β€” a regular SET command overrides any surrounding function's SET option; its effects will persist unless rolled back. she does not care about your function's boundaries, she simply does not. πŸ’…

πŸ“ Note: 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. and yeah, fair, because it WAS unintuitive. 😭

✨ PARAMETERS ✨

okay this is the part where you screenshot and refer back to later, fr fr. πŸ“Έ

  • SESSION β€” specifies that the command takes effect for the current session. (this is the default if neither SESSION nor LOCAL appears. so if you just can't be bothered, the vibes decide for you. πŸ¦‹)
  • LOCAL β€” specifies that the command takes effect for only the current transaction. after COMMIT or ROLLBACK, the session-level setting takes effect again. issuing this outside of a transaction block emits a warning and otherwise has no effect. not her being dramatic with a warning. πŸ™ˆ
  • configuration_parameter β€” name of a settable run-time parameter. available parameters are documented in Chapter 20 and below. iykyk. πŸ’œ
  • value β€” new value of parameter. values can be specified as string constants, identifiers, numbers, or comma-separated lists of these, as appropriate for the particular parameter. DEFAULT can be written to specify resetting the parameter to its default value β€” that is, whatever value it would have had if no SET had been executed in the current session. reset era. πŸŽ€

πŸ’– the special ones πŸ’–

besides the configuration parameters documented in Chapter 20, there are a few that can only be adjusted using the SET command or that have a special syntax. these are the limited-edition drops. πŸ‘‘

SCHEMA

SET SCHEMA 'value' is an alias for SET search_path TO value. only one schema can be specified using this syntax. no bundles, no combos. one schema only. πŸ’…

NAMES

SET NAMES value is an alias for SET client_encoding TO value. cute shorthand, honestly obsessed. ✨

SEED

sets the internal seed for the random number generator (the function random). allowed values are floating-point numbers between -1 and 1 inclusive. so like, stay in the range bestie, it's not a suggestion. πŸ”₯

the seed can also be set by invoking the function setseed:

SELECT setseed(value);

no cap, that's the other way. 🌸

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. it's giving ✨options✨. here are examples of valid values:

  • 'America/Los_Angeles' β€” the time zone for Berkeley, California. cali girl representation. 🌈
  • 'Europe/Rome' β€” the time zone for Italy. ciao. πŸ“
  • -7 β€” the time zone 7 hours west from UTC (equivalent to PDT). positive values are east from UTC. math, but make it geography. πŸ“
  • INTERVAL '-08:00' HOUR TO MINUTE β€” the time zone 8 hours west from UTC (equivalent to PST). the interval flex. 🧚
  • LOCAL / DEFAULT β€” set the time zone to your local time zone (that is, the server's default value of timezone). home sweet home. 🏠

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. that's how she translates, don't question it. πŸ’œ

⚠️ heads up: time zone abbreviations are not supported by SET; see Section 8.5.3 for more information about time zones. so like, don't come for her with abbreviations, she's not doing that. πŸ’€

πŸ“ NOTES πŸ“

the function set_config provides equivalent functionality; see Section 9.27.1. also, it is possible to UPDATE the pg_settings system view to perform the equivalent of SET. multiple paths to the same slay. 🫢


🌟 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';

ate. every single example. πŸ”₯


🧚 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. PostgreSQL said "we can do both, actually." πŸ‘‘

all other SET features are PostgreSQL extensions. house specialty. πŸŽ€


πŸ‘€ SEE ALSO πŸ‘€

RESET(7), SHOW(7) β€” go read those too bestie, they're in the same universe. πŸ’–


and that's the whole page, diva. 🌈 this little love letter came to you courtesy of PostgreSQL 16.15, dated 2026 β€” the docs are timeless, and so are you. πŸŽ€βœ¨πŸ’…πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from