set.sgml 10.5 KB
Newer Older
1
<!--
B
Bruce Momjian 已提交
2
$Header: /cvsroot/pgsql/doc/src/sgml/ref/set.sgml,v 1.50 2000/10/05 19:48:19 momjian Exp $
3 4 5
Postgres documentation
-->

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 13
  <refname>SET</refname>
  <refpurpose>Set run-time parameters</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 68 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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 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
       must be supported by the backend.
      </para>

      <para>
       This option is only available if
       <productname>Postgres</productname> is build with multibyte
       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>
	 <term>Postgres</term>
	 <listitem>
	  <para>
	   Use traditional <productname>Postgres</productname> format.
	  </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
       <quote>SQL</quote> and <quote>Postgres</quote> output formats
       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
198
	    values are floating point numbers between 0 and 1, which
199
	    are then multiplied by 2^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 228 229
	This option is only available if
	<productname>Postgres</productname> was built with multibyte
	support.
230 231 232 233 234
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
235 236
      <term>TIME ZONE</term>
      <term>TIMEZONE</term>
237 238
      <listitem>
       <para>
B
Bruce Momjian 已提交
239
	The possible values for time zone depends on your operating
240 241 242
	system. For example, on Linux
	<filename>/usr/share/zoneinfo</filename> contains the database
	of time zones.
243
       </para>
244
       <para>
B
Bruce Momjian 已提交
245
	Here are some valid values for time zone:
246
				
247 248
	<variablelist>
	 <varlistentry>
249
	  <term>PST8PDT</term>
250 251
	  <listitem>
	   <para>
252
	    Set the time zone for California.
253 254 255
	   </para>
	  </listitem>
	 </varlistentry>
256
	 <varlistentry>
257
	  <term>Portugal</term>
258 259
	  <listitem>
	   <para>
260
	    Set time zone for Portugal.
261 262 263 264
	   </para>
	  </listitem>
	 </varlistentry>
	 <varlistentry>
265
	  <term>'Europe/Rome'</term>
266 267
	  <listitem>
	   <para>
268
	    Set time zone for Italy.
269 270 271 272
	   </para>
	  </listitem>
	 </varlistentry>
	 <varlistentry>
273 274
	  <term>LOCAL</term>
          <term>DEFAULT</term>
275 276
	  <listitem>
	   <para>
277 278
	    Set the time zone to your local time zone (the one that
	    your operating system defaults to).
279 280 281 282 283 284
	   </para>
	  </listitem>
	 </varlistentry>
	</variablelist>
       </para>
       <para>
285 286
	If an invalid time zone is specified, the time zone
	becomes GMT (on most systems anyway).
287
       </para>
288
       <para>
289 290
        If the PGTZ environment variable is set in the frontend
	environment of a client based on libpq, libpq will automatically
B
Bruce Momjian 已提交
291
	set TIMEZONE to the value of PGTZ during connection start-up.
292 293 294 295
       </para>
      </listitem>
     </varlistentry>

296 297
    </variablelist>
   </para>
298

299
  <para>
300 301
   An extended list of other run-time parameters can be found in the
   <citetitle>Administrator's Guide</citetitle>.
302
  </para>
303

304
  <para>
305 306
   Use <xref linkend="SQL-SHOW" endterm="SQL-SHOW-title"> to show the
   current setting of a parameters.
307
  </para>
308 309 310 311 312
  
 </refsect1>

 <refsect1>
  <title>Diagnostics</title>
313
  <para>
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
    
   <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 已提交
344
     <term><computeroutput>ERROR:  <replaceable>name</replaceable> can only be set at start-up</computeroutput></term>
345 346 347 348 349 350 351 352
     <listitem>
      <para>
       Some parameters are fixed once the server is started.
      </para>
     </listitem>
    </varlistentry>
     
   </variablelist>
353
  </para>
354
 </refsect1>
355

356
 
357 358
 <refsect1>
  <title>Examples</title>
359
  <para>
360 361 362 363
   Set the style of date to traditional Postgres with European conventions:
<screen>
SET DATESTYLE TO Postgres,European;
</screen>
364

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

369
<screen> 
370
SET TIME ZONE "PST8PDT";
371
SELECT CURRENT_TIMESTAMP AS today;
372
   
373 374 375
         today
------------------------
 1998-03-31 07:41:21-08
376
</screen>
377

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

381
<screen> 
382 383
SET TIME ZONE 'Europe/Rome';
SELECT CURRENT_TIMESTAMP AS today;
384
   
385 386 387
         today
------------------------
 1998-03-31 17:41:31+02
388
</screen>
389
  </para>
390
 </refsect1>
391

392
 <refsect1 id="R1-SQL-SET-3">
393
  <title>Compatibility</title>
394

395 396 397 398 399 400 401 402 403 404 405 406 407
  <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
    <productname>Postgres</productname> extension.
   </para>
  </refsect2>
408
 </refsect1>
409
</refentry>
410 411 412

<!-- Keep this comment at the end of the file
Local variables:
413
mode:sgml
414 415 416 417 418 419 420 421 422
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
423
sgml-local-catalogs:("/usr/lib/sgml/catalog")
424 425 426
sgml-local-ecat-files:nil
End:
-->