set.sgml 15.2 KB
Newer Older
1
<!--
2
$Header: /cvsroot/pgsql/doc/src/sgml/ref/set.sgml,v 1.63 2002/08/04 03:53:11 momjian 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 18
SET [ SESSION | LOCAL ] <replaceable class="PARAMETER">variable</replaceable> { TO | = } { <replaceable class="PARAMETER">value</replaceable> | '<replaceable class="PARAMETER">value</replaceable>' | DEFAULT }
SET [ SESSION | LOCAL ] 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
   <para>
    <variablelist>
25 26 27 28 29 30

     <varlistentry>
      <term><option>SESSION</></term>
      <listitem>
       <para>
        Specifies that the command takes effect for the current session.
31 32
        (This is the default if neither <option>SESSION</> nor
        <option>LOCAL</> appears.)
33 34 35 36 37 38 39 40 41
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>LOCAL</></term>
      <listitem>
       <para>
        Specifies that the command takes effect for only the current
42 43 44 45 46
        transaction.  After <command>COMMIT</> or <command>ROLLBACK</>,
        the session-level setting takes effect again.  Note that
        <command>SET LOCAL</> will appear to have no effect if it's
        executed outside a <command>BEGIN</> block, since the transaction
        will end immediately.
47 48 49 50
       </para>
      </listitem>
     </varlistentry>

51
     <varlistentry>
52
      <term><replaceable class="PARAMETER">variable</replaceable></term>
53
      <listitem>
54
       <para>
55
        A settable run-time parameter.
56 57 58
       </para>
      </listitem>
     </varlistentry>
59

60
     <varlistentry>
61
      <term><replaceable class="PARAMETER">value</replaceable></term>
62
      <listitem>
63
       <para>
64 65 66 67
        New value of parameter.  <option>DEFAULT</option> can be
        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.
68 69 70 71 72
       </para>
      </listitem>
     </varlistentry>
    </variablelist>
   </para>
73
  </refsect2>
74

75 76 77 78
 </refsynopsisdiv>
 
 <refsect1 id="R1-SQL-SET-1">
  <title>Description</title>
79

80 81
  <para>
   The <command>SET</command> command changes run-time configuration
82 83 84 85 86 87 88
   parameters.  Many of the run-time parameters listed in the
   <citetitle>Administrator's Guide</citetitle> can be changed on-the-fly
   with <command>SET</command>.  (But some require superuser privileges
   to change, and others cannot be changed after server or session start.)
   Note that <command>SET</command> only affects the value used by the
   current session.
  </para>
89

90 91 92 93 94 95 96 97 98 99 100
  <para>
   If <command>SET</command> or <command>SET SESSION</command> is issued
   within a transaction that is later aborted, the effects of the
   <command>SET</command> command disappear when the transaction is rolled
   back.  (This behavior represents a change from
   <productname>PostgreSQL</productname> versions prior to 7.3, where
   the effects of <command>SET</command> would not roll back after a later
   error.)  Once the surrounding transaction is committed, the effects
   will persist until the end of the session, unless overridden by another
   <command>SET</command>.
  </para>
101

102 103 104 105 106 107 108 109 110 111 112 113 114
  <para>
   The effects of <command>SET LOCAL</command> last only till the end of
   the current transaction, whether committed or not.  A special case is
   <command>SET</command> followed by <command>SET LOCAL</command> within
   a single transaction: the <command>SET LOCAL</command> value will be
   seen until the end of the transaction, but afterwards (if the transaction
   is committed) the <command>SET</command> value will take effect.
  </para>

  <para>
   Here are additional details about a few of the parameters that can be set:

   <variablelist>
115 116 117 118 119
    <varlistentry>
     <term>DATESTYLE</term>
     <listitem>
      <para>
       Choose the date/time representation style. Two separate
120
       settings are involved: the default date/time output and the
121 122 123 124 125 126 127
       interpretation of ambiguous input.
      </para>

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

       <variablelist>
128 129 130 131 132 133
        <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.
134
          </para>
135 136
         </listitem>
        </varlistentry>
137 138

        <varlistentry>
139 140 141 142 143 144 145 146 147
         <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>
148 149

        <varlistentry>
150 151 152 153 154 155 156
         <term>PostgreSQL</term>
         <listitem>
          <para>
           Use traditional <productname>PostgreSQL</productname> format.
          </para>
         </listitem>
        </varlistentry>
157 158

        <varlistentry>
159 160 161 162 163 164 165
         <term>German</term>
         <listitem>
          <para>
           Use <literal>dd.mm.yyyy</literal> for numeric date representations.
          </para>
         </listitem>
        </varlistentry>
166 167 168 169 170
       </variablelist>
      </para>

      <para>
       The following two options determine both a substyle of the
171
       <quote>SQL</quote> and <quote>PostgreSQL</quote> output formats
172 173 174
       and the preferred interpretation of ambiguous date input.

       <variablelist>
175 176 177 178 179 180 181 182
        <varlistentry>
         <term>European</term>
         <listitem>
          <para>
           Use <literal>dd/mm/yyyy</literal> for numeric date representations.
          </para>
         </listitem>
        </varlistentry>
183 184

        <varlistentry>
185 186 187 188 189 190 191 192
         <term>NonEuropean</term>
         <term>US</term>
         <listitem>
          <para>
           Use <literal>mm/dd/yyyy</literal> for numeric date representations.
          </para>
         </listitem>
        </varlistentry>
193 194 195 196 197 198 199 200 201 202
       </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>
203 204 205 206 207 208 209 210 211 212 213 214
       <command>SET DATESTYLE</command> affects interpretation of
       input and provides several standard output formats. For
       applications needing different variations or tighter control
       over input or output, consider using
       the <function>to_char</function> family of
       functions.
      </para>

      <para>
       There are several now-deprecated means for setting the datestyle
       in addition to the normal methods of setting it via <command>SET</> or
       a configuration-file entry:
215
       <simplelist>
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
        <member>
         Setting the postmaster's <envar>PGDATESTYLE</envar> environment
         variable.  (This will be overridden by any of the other methods.)
        </member>
        <member>
         Running postmaster using the option <option>-o -e</option> to
         set dates to the <literal>European</literal> convention.
         (This overrides environment variables and configuration-file
         entries.)
        </member>
        <member>
         Setting the client's <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
         value of PGDATESTYLE during connection start-up.  This is
         equivalent to a manually issued <command>SET DATESTYLE</>.
        </member>
233 234
       </simplelist>
      </para>
235

236 237 238 239 240 241
     </listitem>
    </varlistentry>

    <varlistentry>
     <term>NAMES</term>
     <listitem>
242
      <para>
243
       <command>SET NAMES</> is an alias for <command>SET CLIENT_ENCODING</>.
244 245 246
      </para>
     </listitem>
    </varlistentry>
247

248
     <varlistentry>
249
      <term>SEED</term>
250 251
      <listitem>
       <para>
252
       Sets the internal seed for the random number generator.
253
	
254 255 256 257 258 259 260 261 262 263 264 265 266 267
       <variablelist>
        <varlistentry>
         <term><replaceable class="parameter">value</replaceable></term>
         <listitem>
          <para>
           The value for the seed to be used by the
           <function>random</function> function. Allowed
           values are floating-point numbers between 0 and 1, which
           are then multiplied by 2<superscript>31</>-1.
          </para>
         </listitem>
        </varlistentry>
       </variablelist>
      </para>
268

269 270 271
      <para>
       The seed can also be set by invoking the
       <function>setseed</function> SQL function:
272

273
       <programlisting>
274
SELECT setseed(<replaceable>value</replaceable>);
275 276 277 278
       </programlisting>
      </para>
     </listitem>
    </varlistentry>
279

280 281 282 283 284 285 286 287 288 289
    <varlistentry>
     <term>SERVER_ENCODING</term>
     <listitem>
      <para>
       Shows the server-side multibyte encoding.  (At present, this
       parameter can be shown but not set, because the encoding is
       determined at initdb time.)
      </para>
     </listitem>
    </varlistentry>
290

291 292 293 294
    <varlistentry>
     <term>TIME ZONE</term>
     <term>TIMEZONE</term>
     <listitem>
295 296 297
      <para>
       Sets the default time zone for your session. Arguments can be
       an SQL time interval constant, an integer or double precision
298 299
       constant, or a string representing a time zone name recognized
       by the host operating system.
300 301
      </para>

302 303
      <para>
       Here are some typical values for time zone settings:
304 305

       <variablelist>
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
        <varlistentry>
         <term>'PST8PDT'</term>
         <listitem>
          <para>
           Set the time zone for Berkeley, California.
          </para>
         </listitem>
        </varlistentry>
        <varlistentry>
         <term>'Portugal'</term>
         <listitem>
          <para>
           Set the time zone for Portugal.
          </para>
         </listitem>
        </varlistentry>
        <varlistentry>
         <term>'Europe/Rome'</term>
         <listitem>
          <para>
           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>
        <varlistentry>
         <term>INTERVAL '08:00' HOUR TO MINUTE</term>
         <listitem>
          <para>
           Set the time zone to 8 hours offset west from GMT (equivalent
           to PST).
          </para>
         </listitem>
        </varlistentry>
        <varlistentry>
         <term>LOCAL</term>
         <term>DEFAULT</term>
         <listitem>
          <para>
           Set the time zone to your local time zone (the one that
           your operating system defaults to).
          </para>
         </listitem>
        </varlistentry>
       </variablelist>
      </para>
360

361 362 363 364 365 366 367
      <para>
       The available time zone names depend on your operating
       system. For example, on Linux
       <filename>/usr/share/zoneinfo</filename> contains the database
       of time zones; the names of the files in that directory can be
       used as parameters to this command.
      </para>
368

369 370 371 372
      <para>
       If an invalid time zone is specified, the time zone
       becomes GMT (on most systems anyway).
      </para>
373

374 375 376 377 378 379 380 381 382 383
      <para>
       If the <envar>PGTZ</envar> environment variable is set in the frontend
       environment of a client based on libpq, libpq will automatically
       <command>SET TIMEZONE</command> to the value of
       <envar>PGTZ</envar> during connection start-up. 
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
384

385
  <para>
386
   Use <xref linkend="SQL-SHOW" endterm="SQL-SHOW-title"> to show the
387
   current setting of a parameter.
388
  </para>
389 390 391 392 393
  
 </refsect1>

 <refsect1>
  <title>Diagnostics</title>
394
  <para>
395 396 397
    
   <variablelist>
    <varlistentry>
398
     <term><computeroutput>SET</computeroutput></term>
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
     <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>
419
       You must be a superuser to alter certain settings.
420 421 422 423 424
      </para>
     </listitem>
    </varlistentry>
     
    <varlistentry>
B
Bruce Momjian 已提交
425
     <term><computeroutput>ERROR:  <replaceable>name</replaceable> can only be set at start-up</computeroutput></term>
426 427 428 429 430 431 432 433
     <listitem>
      <para>
       Some parameters are fixed once the server is started.
      </para>
     </listitem>
    </varlistentry>
     
   </variablelist>
434
  </para>
435
 </refsect1>
436

437
 
438 439
 <refsect1>
  <title>Examples</title>
440
  <para>
441 442
   Set the style of date to traditional
   <productname>PostgreSQL</productname> with European conventions:
443
   <screen>
444
SET DATESTYLE TO PostgreSQL,European;
445 446
   </screen>
  </para>
447

448 449
  <para>
   Set the time zone for Berkeley, California, using quotes to
450
   preserve the uppercase spelling of the time zone name (note
451 452
   that the date style is <literal>PostgreSQL</literal> for this
   example): 
453

454
   <screen>
455
SET TIME ZONE 'PST8PDT';
456
SELECT CURRENT_TIMESTAMP AS today;
457 458 459 460 461
               today                
------------------------------------
 Tue Feb 26 07:32:21.42834 2002 PST
   </screen>
  </para>
462

463 464
  <para>
   Set the time zone for Italy (note the required single quotes to handle 
465
   the special characters):
466

467
   <screen>
468 469
SET TIME ZONE 'Europe/Rome';
SELECT CURRENT_TIMESTAMP AS today;
470
   
471 472 473
         today
------------------------
 1998-03-31 17:41:31+02
474
   </screen>
475
  </para>
476
 </refsect1>
477

478
 <refsect1 id="R1-SQL-SET-3">
479
  <title>Compatibility</title>
480

481 482 483 484 485 486
  <refsect2 id="R2-SQL-SET-4">
   <title>
    SQL92
   </title>

   <para>
487 488 489 490 491 492
    <literal>SET TIME ZONE</literal>
    extends syntax defined in
    <acronym>SQL9x</acronym>. <acronym>SQL9x</acronym> allows
    only numeric time zone offsets while
    <productname>PostgreSQL</productname> allows full time zone
    specifier strings as well. All other <literal>SET</literal>
493 494
    features are
    <productname>PostgreSQL</productname> extensions.
495 496
   </para>
  </refsect2>
497
 </refsect1>
498 499 500 501 502 503 504 505 506 507

 <refsect1>
  <title>See Also</title>

  <para>
    The function <function>set_config</function> provides the equivalent
    capability. See <citetitle>Miscellaneous Functions</citetitle> in the
    <citetitle>PostgreSQL User's Guide</citetitle>.
  </para>
 </refsect1>
508
</refentry>
509 510 511

<!-- Keep this comment at the end of the file
Local variables:
512
mode:sgml
513 514 515 516 517 518 519 520 521
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
522
sgml-local-catalogs:("/usr/lib/sgml/catalog")
523 524 525
sgml-local-ecat-files:nil
End:
-->