~ubuntu-branches/debian/sid/postgresql-9.3/sid

« back to all changes in this revision

Viewing changes to doc/src/sgml/ref/set.sgml

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2013-05-08 05:39:52 UTC
  • Revision ID: package-import@ubuntu.com-20130508053952-1j7uilp7mjtrvq8q
Tags: upstream-9.3~beta1
ImportĀ upstreamĀ versionĀ 9.3~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!--
 
2
doc/src/sgml/ref/set.sgml
 
3
PostgreSQL documentation
 
4
-->
 
5
 
 
6
<refentry id="SQL-SET">
 
7
 <refmeta>
 
8
  <refentrytitle>SET</refentrytitle>
 
9
  <manvolnum>7</manvolnum>
 
10
  <refmiscinfo>SQL - Language Statements</refmiscinfo>
 
11
 </refmeta>
 
12
 
 
13
 <refnamediv>
 
14
  <refname>SET</refname>
 
15
  <refpurpose>change a run-time parameter</refpurpose>
 
16
 </refnamediv>
 
17
 
 
18
 <indexterm zone="sql-set">
 
19
  <primary>SET</primary>
 
20
 </indexterm>
 
21
 
 
22
 <refsynopsisdiv>
 
23
<synopsis>
 
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 }
 
26
</synopsis>
 
27
 </refsynopsisdiv>
 
28
 
 
29
 <refsect1>
 
30
  <title>Description</title>
 
31
 
 
32
  <para>
 
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
 
40
   session.
 
41
  </para>
 
42
 
 
43
  <para>
 
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>.
 
50
  </para>
 
51
 
 
52
  <para>
 
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.
 
59
  </para>
 
60
 
 
61
  <para>
 
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
 
64
   command.
 
65
  </para>
 
66
 
 
67
  <para>
 
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.
 
79
  </para>
 
80
 
 
81
  <note>
 
82
   <para>
 
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.
 
88
   </para>
 
89
  </note>
 
90
 </refsect1>
 
91
 
 
92
 <refsect1>
 
93
  <title>Parameters</title>
 
94
 
 
95
  <variablelist>
 
96
   <varlistentry>
 
97
    <term><literal>SESSION</></term>
 
98
    <listitem>
 
99
     <para>
 
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.)
 
103
     </para>
 
104
    </listitem>
 
105
   </varlistentry>
 
106
 
 
107
   <varlistentry>
 
108
    <term><literal>LOCAL</></term>
 
109
    <listitem>
 
110
     <para>
 
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.
 
117
     </para>
 
118
    </listitem>
 
119
   </varlistentry>
 
120
 
 
121
   <varlistentry>
 
122
    <term><replaceable class="PARAMETER">configuration_parameter</replaceable></term>
 
123
    <listitem>
 
124
     <para>
 
125
      Name of a settable run-time parameter.  Available parameters are
 
126
      documented in <xref linkend="runtime-config"> and below.
 
127
     </para>
 
128
    </listitem>
 
129
   </varlistentry>
 
130
 
 
131
   <varlistentry>
 
132
    <term><replaceable class="PARAMETER">value</replaceable></term>
 
133
    <listitem>
 
134
     <para>
 
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).
 
142
     </para>
 
143
    </listitem>
 
144
   </varlistentry>
 
145
  </variablelist>
 
146
 
 
147
  <para>
 
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
 
151
   special syntax:
 
152
 
 
153
   <variablelist>
 
154
    <varlistentry>
 
155
     <term><literal>SCHEMA</literal></term>
 
156
     <listitem>
 
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.
 
160
      </para>
 
161
     </listitem>
 
162
    </varlistentry>
 
163
 
 
164
    <varlistentry>
 
165
     <term><literal>NAMES</literal></term>
 
166
     <listitem>
 
167
      <para><literal>SET NAMES <replaceable>value</></> is an alias for
 
168
       <literal>SET client_encoding TO <replaceable>value</></>.
 
169
      </para>
 
170
     </listitem>
 
171
    </varlistentry>
 
172
 
 
173
    <varlistentry>
 
174
     <term><literal>SEED</literal></term>
 
175
     <listitem>
 
176
      <para>
 
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.
 
181
      </para>
 
182
 
 
183
      <para>
 
184
       The seed can also be set by invoking the function
 
185
       <function>setseed</function>:
 
186
<programlisting>
 
187
SELECT setseed(<replaceable>value</replaceable>);
 
188
</programlisting></para>
 
189
     </listitem>
 
190
    </varlistentry>
 
191
 
 
192
    <varlistentry>
 
193
     <term><literal>TIME ZONE</literal></term>
 
194
     <listitem>
 
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
 
199
       values:
 
200
 
 
201
       <variablelist>
 
202
        <varlistentry>
 
203
         <term><literal>'PST8PDT'</literal></term>
 
204
         <listitem>
 
205
          <para>
 
206
           The time zone for Berkeley, California.
 
207
          </para>
 
208
         </listitem>
 
209
        </varlistentry>
 
210
        <varlistentry>
 
211
         <term><literal>'Europe/Rome'</literal></term>
 
212
         <listitem>
 
213
          <para>
 
214
           The time zone for Italy.
 
215
          </para>
 
216
         </listitem>
 
217
        </varlistentry>
 
218
        <varlistentry>
 
219
         <term><literal>-7</literal></term>
 
220
         <listitem>
 
221
          <para>
 
222
           The time zone 7 hours west from UTC (equivalent
 
223
           to PDT).  Positive values are east from UTC.
 
224
          </para>
 
225
         </listitem>
 
226
        </varlistentry>
 
227
        <varlistentry>
 
228
         <term><literal>INTERVAL '-08:00' HOUR TO MINUTE</literal></term>
 
229
         <listitem>
 
230
          <para>
 
231
           The time zone 8 hours west from UTC (equivalent
 
232
           to PST).
 
233
          </para>
 
234
         </listitem>
 
235
        </varlistentry>
 
236
        <varlistentry>
 
237
         <term><literal>LOCAL</literal></term>
 
238
         <term><literal>DEFAULT</literal></term>
 
239
         <listitem>
 
240
          <para>
 
241
           Set the time zone to your local time zone (that is, the
 
242
           server's default value of <varname>timezone</>).
 
243
          </para>
 
244
         </listitem>
 
245
        </varlistentry>
 
246
       </variablelist>
 
247
 
 
248
       See <xref linkend="datatype-timezones"> for more information
 
249
       about time zones.
 
250
      </para>
 
251
     </listitem>
 
252
    </varlistentry>
 
253
   </variablelist>
 
254
  </para>
 
255
 </refsect1>
 
256
 
 
257
 <refsect1>
 
258
  <title>Notes</title>
 
259
 
 
260
  <para>
 
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</>.
 
266
  </para>
 
267
 </refsect1>
 
268
 
 
269
 <refsect1>
 
270
  <title>Examples</title>
 
271
 
 
272
  <para>
 
273
   Set the schema search path:
 
274
<programlisting>
 
275
SET search_path TO my_schema, public;
 
276
</programlisting>
 
277
  </para>
 
278
 
 
279
  <para>
 
280
   Set the style of date to traditional
 
281
   <productname>POSTGRES</productname> with <quote>day before month</>
 
282
   input convention:
 
283
<screen>
 
284
SET datestyle TO postgres, dmy;
 
285
</screen>
 
286
  </para>
 
287
 
 
288
  <para>
 
289
   Set the time zone for Berkeley, California:
 
290
<screen>
 
291
SET TIME ZONE 'PST8PDT';
 
292
</screen>
 
293
  </para>
 
294
 
 
295
  <para>
 
296
   Set the time zone for Italy:
 
297
<screen>
 
298
SET TIME ZONE 'Europe/Rome';
 
299
</screen></para>
 
300
 </refsect1>
 
301
 
 
302
 <refsect1>
 
303
  <title>Compatibility</title>
 
304
 
 
305
  <para>
 
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.
 
311
  </para>
 
312
 </refsect1>
 
313
 
 
314
 <refsect1>
 
315
  <title>See Also</title>
 
316
 
 
317
  <simplelist type="inline">
 
318
   <member><xref linkend="SQL-RESET"></member>
 
319
   <member><xref linkend="SQL-SHOW"></member>
 
320
  </simplelist>
 
321
 </refsect1>
 
322
</refentry>