]> begriffs open source - ai-pg/blob - full-docs/txt/sql-set.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / sql-set.txt
1
2 SET
3
4    SET — change a run-time parameter
5
6 Synopsis
7
8 SET [ SESSION | LOCAL ] configuration_parameter { TO | = } { value | 'value' | D
9 EFAULT }
10 SET [ SESSION | LOCAL ] TIME ZONE { value | 'value' | LOCAL | DEFAULT }
11
12 Description
13
14    The SET command changes run-time configuration parameters. Many of the
15    run-time parameters listed in Chapter 19 can be changed on-the-fly with
16    SET. (Some parameters can only be changed by superusers and users who
17    have been granted SET privilege on that parameter. There are also
18    parameters that cannot be changed after server or session start.) SET
19    only affects the value used by the current session.
20
21    If SET (or equivalently SET SESSION) is issued within a transaction
22    that is later aborted, the effects of the SET command disappear when
23    the transaction is rolled back. Once the surrounding transaction is
24    committed, the effects will persist until the end of the session,
25    unless overridden by another SET.
26
27    The effects of SET LOCAL last only till the end of the current
28    transaction, whether committed or not. A special case is SET followed
29    by SET LOCAL within a single transaction: the SET LOCAL value will be
30    seen until the end of the transaction, but afterwards (if the
31    transaction is committed) the SET value will take effect.
32
33    The effects of SET or SET LOCAL are also canceled by rolling back to a
34    savepoint that is earlier than the command.
35
36    If SET LOCAL is used within a function that has a SET option for the
37    same variable (see CREATE FUNCTION), the effects of the SET LOCAL
38    command disappear at function exit; that is, the value in effect when
39    the function was called is restored anyway. This allows SET LOCAL to be
40    used for dynamic or repeated changes of a parameter within a function,
41    while still having the convenience of using the SET option to save and
42    restore the caller's value. However, a regular SET command overrides
43    any surrounding function's SET option; its effects will persist unless
44    rolled back.
45
46 Note
47
48    In PostgreSQL versions 8.0 through 8.2, the effects of a SET LOCAL
49    would be canceled by releasing an earlier savepoint, or by successful
50    exit from a PL/pgSQL exception block. This behavior has been changed
51    because it was deemed unintuitive.
52
53 Parameters
54
55    SESSION
56           Specifies that the command takes effect for the current session.
57           (This is the default if neither SESSION nor LOCAL appears.)
58
59    LOCAL
60           Specifies that the command takes effect for only the current
61           transaction. After COMMIT or ROLLBACK, the session-level setting
62           takes effect again. Issuing this outside of a transaction block
63           emits a warning and otherwise has no effect.
64
65    configuration_parameter
66           Name of a settable run-time parameter. Available parameters are
67           documented in Chapter 19 and below.
68
69    value
70           New value of parameter. Values can be specified as string
71           constants, identifiers, numbers, or comma-separated lists of
72           these, as appropriate for the particular parameter. DEFAULT can
73           be written to specify resetting the parameter to its default
74           value (that is, whatever value it would have had if no SET had
75           been executed in the current session).
76
77    Besides the configuration parameters documented in Chapter 19, there
78    are a few that can only be adjusted using the SET command or that have
79    a special syntax:
80
81    SCHEMA
82           SET SCHEMA 'value' is an alias for SET search_path TO value.
83           Only one schema can be specified using this syntax.
84
85    NAMES
86           SET NAMES 'value' is an alias for SET client_encoding TO value.
87
88    SEED
89           Sets the internal seed for the random number generator (the
90           function random). Allowed values are floating-point numbers
91           between -1 and 1 inclusive.
92
93           The seed can also be set by invoking the function setseed:
94
95 SELECT setseed(value);
96
97    TIME ZONE
98           SET TIME ZONE 'value' is an alias for SET timezone TO 'value'.
99           The syntax SET TIME ZONE allows special syntax for the time zone
100           specification. Here are examples of valid values:
101
102         'America/Los_Angeles'
103                 The time zone for Berkeley, California.
104
105         'Europe/Rome'
106                 The time zone for Italy.
107
108         -7
109                 The time zone 7 hours west from UTC (equivalent to PDT).
110                 Positive values are east from UTC.
111
112         INTERVAL '-08:00' HOUR TO MINUTE
113                 The time zone 8 hours west from UTC (equivalent to PST).
114
115         LOCAL
116                 DEFAULT
117                 Set the time zone to your local time zone (that is, the
118                 server's default value of timezone).
119
120           Timezone settings given as numbers or intervals are internally
121           translated to POSIX timezone syntax. For example, after SET TIME
122           ZONE -7, SHOW TIME ZONE would report <-07>+07.
123
124           Time zone abbreviations are not supported by SET; see
125           Section 8.5.3 for more information about time zones.
126
127 Notes
128
129    The function set_config provides equivalent functionality; see
130    Section 9.28.1. Also, it is possible to UPDATE the pg_settings system
131    view to perform the equivalent of SET.
132
133 Examples
134
135    Set the schema search path:
136 SET search_path TO my_schema, public;
137
138    Set the style of date to traditional POSTGRES with “day before month”
139    input convention:
140 SET datestyle TO postgres, dmy;
141
142    Set the time zone for Berkeley, California:
143 SET TIME ZONE 'America/Los_Angeles';
144
145    Set the time zone for Italy:
146 SET TIME ZONE 'Europe/Rome';
147
148 Compatibility
149
150    SET TIME ZONE extends syntax defined in the SQL standard. The standard
151    allows only numeric time zone offsets while PostgreSQL allows more
152    flexible time-zone specifications. All other SET features are
153    PostgreSQL extensions.
154
155 See Also
156
157    RESET, SHOW