set.sgml 11.3 KB
Newer Older
1
<!--
2
$Header: /cvsroot/pgsql/doc/src/sgml/ref/set.sgml,v 1.58 2002/02/26 15:59:08 tgl Exp $
3
PostgreSQL documentation
4 5
-->

6 7
<refentry id="SQL-SET">
 <refmeta>
8
  <refentrytitle id="SQL-SET-TITLE">SET</refentrytitle>
9 10 11
  <refmiscinfo>SQL - Language Statements</refmiscinfo>
 </refmeta>
 <refnamediv>
12
  <refname>SET</refname>
13
  <refpurpose>change a run-time parameter</refpurpose>
14
 </refnamediv>
15 16
 <refsynopsisdiv>
  <synopsis>
17
SET <replaceable class="PARAMETER">variable</replaceable> { TO | = } { <replaceable class="PARAMETER">value</replaceable> | '<replaceable class="PARAMETER">value</replaceable>' | DEFAULT }
18
SET TIME ZONE { '<replaceable class="PARAMETER">timezone</replaceable>' | LOCAL | DEFAULT }
19
  </synopsis>
20

21
  <refsect2 id="R2-SQL-SET-1">
22
   <title>Inputs</title>
23 24 25
   <para>
    <variablelist>
     <varlistentry>
26
      <term><replaceable class="PARAMETER">variable</replaceable></term>
27
      <listitem>
28
       <para>
29
	A settable run-time parameter.
30 31 32 33
       </para>
      </listitem>
     </varlistentry>
     <varlistentry>
34
      <term><replaceable class="PARAMETER">value</replaceable></term>
35
      <listitem>
36
       <para>
37
	New value of parameter.  <option>DEFAULT</option> can be
38 39 40
	used to specify resetting the parameter to its default
	value. Lists of strings are allowed, but more complex
	constructs may need to be single or double quoted.
41 42 43 44 45
       </para>
      </listitem>
     </varlistentry>
    </variablelist>
   </para>
46
  </refsect2>
47

48 49 50 51 52 53 54 55 56 57 58 59 60 61
 </refsynopsisdiv>
 
 <refsect1 id="R1-SQL-SET-1">
  <title>Description</title>
  <para>
   The <command>SET</command> command changes run-time configuration
   parameters. The following parameters can be altered:

   <variablelist>
    <varlistentry>
     <term>CLIENT_ENCODING</term>
     <term>NAMES</term>
     <listitem>
      <para>
B
Bruce Momjian 已提交
62
       Sets the multibyte client encoding. The specified encoding
63 64 65 66 67
       must be supported by the backend.
      </para>

      <para>
       This option is only available if
68
       <productname>PostgreSQL</productname> is build with multibyte
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
       support.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry>
     <term>DATESTYLE</term>
     <listitem>
      <para>
       Choose the date/time representation style. Two separate
       settings are made: the default date/time output and the
       interpretation of ambiguous input.
      </para>

      <para>
       The following are date/time output styles:

       <variablelist>
	<varlistentry>
	 <term>ISO</term>
	 <listitem>
	  <para>
	   Use ISO 8601-style dates and times (<literal>YYYY-MM-DD
	   HH:MM:SS</literal>). This is the default.
          </para>
	 </listitem>
	</varlistentry>

        <varlistentry>
	 <term>SQL</term>
	 <listitem>
	  <para>
	   Use Oracle/Ingres-style dates and times. Note that this
	   style has nothing to do with SQL (which mandates ISO 8601
	   style), the naming of this option is a historical accident.
	  </para>
	 </listitem>
	</varlistentry>

        <varlistentry>
109
	 <term>PostgreSQL</term>
110 111
	 <listitem>
	  <para>
112
	   Use traditional <productname>PostgreSQL</productname> format.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
	  </para>
	 </listitem>
	</varlistentry>

        <varlistentry>
	 <term>German</term>
	 <listitem>
	  <para>
	   Use <literal>dd.mm.yyyy</literal> for numeric date representations.
	  </para>
	 </listitem>
	</varlistentry>
       </variablelist>
      </para>

      <para>
       The following two options determine both a substyle of the
130
       <quote>SQL</quote> and <quote>PostgreSQL</quote> output formats
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
       and the preferred interpretation of ambiguous date input.

       <variablelist>
	<varlistentry>
	 <term>European</term>
	 <listitem>
	  <para>
	   Use <literal>dd/mm/yyyy</literal> for numeric date representations.
	  </para>
	 </listitem>
	</varlistentry>

        <varlistentry>
	 <term>NonEuropean</term>
	 <term>US</term>
	 <listitem>
	  <para>
	   Use <literal>mm/dd/yyyy</literal> for numeric date representations.
	  </para>
	 </listitem>
	</varlistentry>
       </variablelist>
      </para>

      <para>
       A value for <command>SET DATESTYLE</command> can be one from
       the first list (output styles), or one from the second list
       (substyles), or one from each separated by a comma.
      </para>

      <para>
       Date format initialization may be done by:
       <simplelist>
	<member>
	 Setting the <envar>PGDATESTYLE</envar> environment variable.
	 If PGDATESTYLE is set in the frontend environment of a client
	 based on libpq, libpq will automatically set DATESTYLE to the
B
Bruce Momjian 已提交
168
	 value of PGDATESTYLE during connection start-up.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
	</member>
	<member>
	 Running postmaster using the option <option>-o -e</option> to
	 set dates to the <literal>European</literal> convention.
	</member>
       </simplelist>
      </para>
      <para>
       The <option>DateStyle</option> option is really only intended
       for porting applications. To format your date/time values to
       choice, use the <function>to_char</function> family of
       functions.
      </para>
     </listitem>
    </varlistentry>
184

185
     <varlistentry>
186
      <term>SEED</term>
187 188
      <listitem>
       <para>
189
	Sets the internal seed for the random number generator.
190 191 192
	
	<variablelist>
	 <varlistentry>
193
	  <term><replaceable class="parameter">value</replaceable></term>
194 195
	  <listitem>
	   <para>
196
	    The value for the seed to be used by the
197
	    <function>random</function> function. Allowed
P
Peter Eisentraut 已提交
198 199
	    values are floating-point numbers between 0 and 1, which
	    are then multiplied by 2<superscript>31</>-1. This product will
200
	    silently overflow if a number outside the range is used.
201
	   </para>
202

203
	   <para>
204 205
	    The seed can also be set by invoking the
	    <function>setseed</function> SQL function:
206

207 208 209
	    <programlisting>
SELECT setseed(<replaceable>value</replaceable>);
	    </programlisting>
210 211 212 213 214
	   </para>
	  </listitem>
	 </varlistentry>
	</variablelist>
       </para>
215

216 217
      </listitem>
     </varlistentry>
218

219
     <varlistentry>
220
      <term>SERVER_ENCODING</term>
221 222
      <listitem>
       <para>
B
Bruce Momjian 已提交
223
	Sets the multibyte server encoding.
224 225 226
       </para>

       <para>
227
	This option is only available if
228
	<productname>PostgreSQL</productname> was built with multibyte
229
	support.
230 231 232 233 234
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
235 236
      <term>TIME ZONE</term>
      <term>TIMEZONE</term>
237
      <listitem>
238 239 240 241 242 243 244
      <para>
       Sets the default time zone for your session. Arguments can be
       an SQL time interval constant, an integer or double precision
       constant, or a string representing a time zone supported by
       the host operating system.
      </para>

245
       <para>
B
Bruce Momjian 已提交
246
	The possible values for time zone depends on your operating
247 248 249
	system. For example, on Linux
	<filename>/usr/share/zoneinfo</filename> contains the database
	of time zones.
250
       </para>
251
       <para>
B
Bruce Momjian 已提交
252
	Here are some valid values for time zone:
253 254

       <variablelist>
255
	 <varlistentry>
256
	  <term>'PST8PDT'</term>
257 258
	  <listitem>
	   <para>
259
	    Set the time zone for California.
260 261 262
	   </para>
	  </listitem>
	 </varlistentry>
263
	 <varlistentry>
264
	  <term>'Portugal'</term>
265 266
	  <listitem>
	   <para>
267
	    Set the time zone for Portugal.
268 269 270 271
	   </para>
	  </listitem>
	 </varlistentry>
	 <varlistentry>
272
	  <term>'Europe/Rome'</term>
273 274
	  <listitem>
	   <para>
275 276 277 278 279 280 281 282 283 284 285 286 287
	    Set the time zone for Italy.
	   </para>
	  </listitem>
	 </varlistentry>
	 <varlistentry>
	  <term>7</term>
	  <listitem>
	   <para>
	    Set the time zone to 7 hours offset west from GMT (equivalent
	   to PDT).
	   </para>
	  </listitem>
	 </varlistentry>
288
	 <varlistentry>
289 290 291 292 293
	  <term>INTERVAL '08:00' HOUR TO MINUTE</term>
	  <listitem>
	   <para>
	    Set the time zone to 8 hours offset west from GMT (equivalent
	   to PST).
294 295 296 297
	   </para>
	  </listitem>
	 </varlistentry>
	 <varlistentry>
298 299
	  <term>LOCAL</term>
          <term>DEFAULT</term>
300 301
	  <listitem>
	   <para>
302 303
	    Set the time zone to your local time zone (the one that
	    your operating system defaults to).
304 305 306 307 308 309
	   </para>
	  </listitem>
	 </varlistentry>
	</variablelist>
       </para>
       <para>
310 311
	If an invalid time zone is specified, the time zone
	becomes GMT (on most systems anyway).
312
       </para>
313
       <para>
314
        If the <envar>PGTZ</envar> environment variable is set in the frontend
315
	environment of a client based on libpq, libpq will automatically
316
	set TIMEZONE to the value of <envar>PGTZ</envar> during connection start-up.
317 318 319 320
       </para>
      </listitem>
     </varlistentry>

321 322
    </variablelist>
   </para>
323

324
  <para>
325 326
   An extended list of other run-time parameters can be found in the
   <citetitle>Administrator's Guide</citetitle>.
327
  </para>
328

329
  <para>
330 331
   Use <xref linkend="SQL-SHOW" endterm="SQL-SHOW-title"> to show the
   current setting of a parameters.
332
  </para>
333 334 335 336 337
  
 </refsect1>

 <refsect1>
  <title>Diagnostics</title>
338
  <para>
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
    
   <variablelist>
    <varlistentry>
     <term><computeroutput>SET VARIABLE</computeroutput></term>
     <listitem>
      <para>
       Message returned if successful.
      </para>
     </listitem>
    </varlistentry>
     
    <varlistentry>
     <term><computeroutput>ERROR:  not a valid option name: <replaceable>name</replaceable></computeroutput></term>
     <listitem>
      <para>
       The parameter you tried to set does not exist.
      </para>
     </listitem>
    </varlistentry>
     
    <varlistentry>
     <term><computeroutput>ERROR:  permission denied</computeroutput></term>
     <listitem>
      <para>
       You must be a superuser to have access to certain settings.
      </para>
     </listitem>
    </varlistentry>
     
    <varlistentry>
B
Bruce Momjian 已提交
369
     <term><computeroutput>ERROR:  <replaceable>name</replaceable> can only be set at start-up</computeroutput></term>
370 371 372 373 374 375 376 377
     <listitem>
      <para>
       Some parameters are fixed once the server is started.
      </para>
     </listitem>
    </varlistentry>
     
   </variablelist>
378
  </para>
379
 </refsect1>
380

381
 
382 383
 <refsect1>
  <title>Examples</title>
384
  <para>
385 386
   Set the style of date to traditional
   <productname>PostgreSQL</productname> with European conventions:
387
<screen>
388
SET DATESTYLE TO PostgreSQL,European;
389
</screen>
390

B
Bruce Momjian 已提交
391
   Set the time zone for Berkeley, California, using double quotes to
392 393
   preserve the uppercase attributes of the time zone specifier (note
   that the date/time format is ISO here):
394

395
<screen> 
396
SET TIME ZONE 'PST8PDT';
397
SELECT CURRENT_TIMESTAMP AS today;
398
   
399 400 401
         today
------------------------
 1998-03-31 07:41:21-08
402
</screen>
403

B
Bruce Momjian 已提交
404
   Set the time zone for Italy (note the required single or double quotes to handle 
405
   the special characters):
406

407
<screen> 
408 409
SET TIME ZONE 'Europe/Rome';
SELECT CURRENT_TIMESTAMP AS today;
410
   
411 412 413
         today
------------------------
 1998-03-31 17:41:31+02
414
</screen>
415
  </para>
416
 </refsect1>
417

418
 <refsect1 id="R1-SQL-SET-3">
419
  <title>Compatibility</title>
420

421 422 423 424 425 426 427 428 429 430
  <refsect2 id="R2-SQL-SET-4">
   <title>
    SQL92
   </title>

   <para>
    The second syntax shown above (<literal>SET TIME ZONE</literal>)
    attempts to mimic <acronym>SQL92</acronym>. However, SQL allows
    only numeric time zone offsets. All other parameter settings as
    well as the first syntax shown above are a
431
    <productname>PostgreSQL</productname> extension.
432 433
   </para>
  </refsect2>
434
 </refsect1>
435
</refentry>
436 437 438

<!-- Keep this comment at the end of the file
Local variables:
439
mode:sgml
440 441 442 443 444 445 446 447 448
sgml-omittag:nil
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../reference.ced"
sgml-exposed-tags:nil
449
sgml-local-catalogs:("/usr/lib/sgml/catalog")
450 451 452
sgml-local-ecat-files:nil
End:
-->