2
doc/src/sgml/ref/set.sgml
3
PostgreSQL documentation
6
<refentry id="SQL-SET">
8
<refentrytitle>SET</refentrytitle>
9
<manvolnum>7</manvolnum>
10
<refmiscinfo>SQL - Language Statements</refmiscinfo>
14
<refname>SET</refname>
15
<refpurpose>change a run-time parameter</refpurpose>
18
<indexterm zone="sql-set">
19
<primary>SET</primary>
24
SET [ SESSION | LOCAL ] <replaceable class="PARAMETER">configuration_parameter</replaceable> { TO | = } { <replaceable class="PARAMETER">value</replaceable> | '<replaceable class="PARAMETER">value</replaceable>' | DEFAULT }
25
SET [ SESSION | LOCAL ] TIME ZONE { <replaceable class="PARAMETER">timezone</replaceable> | LOCAL | DEFAULT }
30
<title>Description</title>
33
The <command>SET</command> command changes run-time configuration
34
parameters. Many of the run-time parameters listed in
35
<xref linkend="runtime-config"> can be changed on-the-fly with
36
<command>SET</command>.
37
(But some require superuser privileges to change, and others cannot
38
be changed after server or session start.)
39
<command>SET</command> only affects the value used by the current
44
If <command>SET</command> (or equivalently <command>SET SESSION</command>)
45
is issued within a transaction that is later aborted, the effects of the
46
<command>SET</command> command disappear when the transaction is rolled
47
back. Once the surrounding transaction is committed, the effects
48
will persist until the end of the session, unless overridden by another
49
<command>SET</command>.
53
The effects of <command>SET LOCAL</command> last only till the end of
54
the current transaction, whether committed or not. A special case is
55
<command>SET</command> followed by <command>SET LOCAL</command> within
56
a single transaction: the <command>SET LOCAL</command> value will be
57
seen until the end of the transaction, but afterwards (if the transaction
58
is committed) the <command>SET</command> value will take effect.
62
The effects of <command>SET</command> or <command>SET LOCAL</command> are
63
also canceled by rolling back to a savepoint that is earlier than the
68
If <command>SET LOCAL</command> is used within a function that has a
69
<literal>SET</> option for the same variable (see
70
<xref linkend="sql-createfunction">),
71
the effects of the <command>SET LOCAL</command> command disappear at
72
function exit; that is, the value in effect when the function was called is
73
restored anyway. This allows <command>SET LOCAL</command> to be used for
74
dynamic or repeated changes of a parameter within a function, while still
75
having the convenience of using the <literal>SET</> option to save and
76
restore the caller's value. However, a regular <command>SET</> command
77
overrides any surrounding function's <literal>SET</> option; its effects
78
will persist unless rolled back.
83
In <productname>PostgreSQL</productname> versions 8.0 through 8.2,
84
the effects of a <command>SET LOCAL</command> would be canceled by
85
releasing an earlier savepoint, or by successful exit from a
86
<application>PL/pgSQL</application> exception block. This behavior
87
has been changed because it was deemed unintuitive.
93
<title>Parameters</title>
97
<term><literal>SESSION</></term>
100
Specifies that the command takes effect for the current session.
101
(This is the default if neither <literal>SESSION</> nor
102
<literal>LOCAL</> appears.)
108
<term><literal>LOCAL</></term>
111
Specifies that the command takes effect for only the current
112
transaction. After <command>COMMIT</> or <command>ROLLBACK</>,
113
the session-level setting takes effect again. Note that
114
<command>SET LOCAL</> will appear to have no effect if it is
115
executed outside a <command>BEGIN</> block, since the
116
transaction will end immediately.
122
<term><replaceable class="PARAMETER">configuration_parameter</replaceable></term>
125
Name of a settable run-time parameter. Available parameters are
126
documented in <xref linkend="runtime-config"> and below.
132
<term><replaceable class="PARAMETER">value</replaceable></term>
135
New value of parameter. Values can be specified as string
136
constants, identifiers, numbers, or comma-separated lists of
137
these, as appropriate for the particular parameter.
138
<literal>DEFAULT</literal> can be written to specify
139
resetting the parameter to its default value (that is, whatever
140
value it would have had if no <command>SET</> had been executed
141
in the current session).
148
Besides the configuration parameters documented in <xref
149
linkend="runtime-config">, there are a few that can only be
150
adjusted using the <command>SET</command> command or that have a
155
<term><literal>SCHEMA</literal></term>
157
<para><literal>SET SCHEMA '<replaceable>value</>'</> is an alias for
158
<literal>SET search_path TO <replaceable>value</></>. Only one
159
schema can be specified using this syntax.
165
<term><literal>NAMES</literal></term>
167
<para><literal>SET NAMES <replaceable>value</></> is an alias for
168
<literal>SET client_encoding TO <replaceable>value</></>.
174
<term><literal>SEED</literal></term>
177
Sets the internal seed for the random number generator (the
178
function <function>random</function>). Allowed values are
179
floating-point numbers between -1 and 1, which are then
180
multiplied by 2<superscript>31</>-1.
184
The seed can also be set by invoking the function
185
<function>setseed</function>:
187
SELECT setseed(<replaceable>value</replaceable>);
188
</programlisting></para>
193
<term><literal>TIME ZONE</literal></term>
195
<para><literal>SET TIME ZONE <replaceable>value</></> is an alias
196
for <literal>SET timezone TO <replaceable>value</></>. The
197
syntax <literal>SET TIME ZONE</literal> allows special syntax
198
for the time zone specification. Here are examples of valid
203
<term><literal>'PST8PDT'</literal></term>
206
The time zone for Berkeley, California.
211
<term><literal>'Europe/Rome'</literal></term>
214
The time zone for Italy.
219
<term><literal>-7</literal></term>
222
The time zone 7 hours west from UTC (equivalent
223
to PDT). Positive values are east from UTC.
228
<term><literal>INTERVAL '-08:00' HOUR TO MINUTE</literal></term>
231
The time zone 8 hours west from UTC (equivalent
237
<term><literal>LOCAL</literal></term>
238
<term><literal>DEFAULT</literal></term>
241
Set the time zone to your local time zone (that is, the
242
server's default value of <varname>timezone</>).
248
See <xref linkend="datatype-timezones"> for more information
261
The function <function>set_config</function> provides equivalent
262
functionality; see <xref linkend="functions-admin">.
263
Also, it is possible to UPDATE the
264
<link linkend="view-pg-settings"><structname>pg_settings</structname></link>
265
system view to perform the equivalent of <command>SET</>.
270
<title>Examples</title>
273
Set the schema search path:
275
SET search_path TO my_schema, public;
280
Set the style of date to traditional
281
<productname>POSTGRES</productname> with <quote>day before month</>
284
SET datestyle TO postgres, dmy;
289
Set the time zone for Berkeley, California:
291
SET TIME ZONE 'PST8PDT';
296
Set the time zone for Italy:
298
SET TIME ZONE 'Europe/Rome';
303
<title>Compatibility</title>
306
<literal>SET TIME ZONE</literal> extends syntax defined in the SQL
307
standard. The standard allows only numeric time zone offsets while
308
<productname>PostgreSQL</productname> allows more flexible
309
time-zone specifications. All other <literal>SET</literal>
310
features are <productname>PostgreSQL</productname> extensions.
315
<title>See Also</title>
317
<simplelist type="inline">
318
<member><xref linkend="SQL-RESET"></member>
319
<member><xref linkend="SQL-SHOW"></member>