set.sgml 16.8 KB
Newer Older
1 2 3
<refentry id="SQL-SET">
 <refmeta>
  <refentrytitle>
4
   SET
5 6 7 8 9
  </refentrytitle>
  <refmiscinfo>SQL - Language Statements</refmiscinfo>
 </refmeta>
 <refnamediv>
  <refname>
10
   SET
11 12
  </refname>
  <refpurpose>
13
   Set run-time parameters for session
14
  </refpurpose>
15
 </refnamediv>
16 17 18 19 20 21 22 23 24
 <refsynopsisdiv>
  <refsynopsisdivinfo>
   <date>1998-09-24</date>
  </refsynopsisdivinfo>
  <synopsis>
SET <replaceable class="PARAMETER">variable</replaceable> { TO | = } { '<replaceable class="PARAMETER">value</replaceable>' | DEFAULT }
SET TIME ZONE { '<replaceable class="PARAMETER">timezone</replaceable>' | LOCAL | DEFAULT };
SET TRANSACTION ISOLATION LEVEL { READ COMMITTED | SERIALIZED | DEFAULT }
  </synopsis>
25

26 27 28 29 30
  <refsect2 id="R2-SQL-SET-1">
   <refsect2info>
    <date>1998-09-24</date>
   </refsect2info>
   <title>
31
    Inputs
32 33
   </title>
   <para>
34
		
35 36 37 38 39 40
    <variablelist>
     <varlistentry>
      <term>
       <replaceable class="PARAMETER">variable</replaceable>
      </term>
      <listitem>
41 42 43 44 45 46 47
       <para>
	Settable global parameter.
       </para>
      </listitem>
     </varlistentry>
     <varlistentry>
      <term>
48
       <replaceable class="PARAMETER">value</replaceable>
49 50
      </term>
      <listitem>
51
       <para>
52 53 54 55 56 57
	New value of parameter.
       </para>
      </listitem>
     </varlistentry>
    </variablelist>
   </para>
58

59 60
   <para>
    The possible variables and allowed values are:
61
		
62 63 64 65 66 67 68 69
    <variablelist>
     <varlistentry>
      <term>
       CLIENT_ENCODING | NAMES
      </term>
      <listitem>
       <para>
	Sets the multi-byte client encoding
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
	<variablelist>
	 <varlistentry>
	  <term>
	   <replaceable class="parameter">value</replaceable>
	  </term>
	  <listitem>
	   <para>
	    Sets the multi-byte client encoding to
	    <replaceable class="parameter">value</replaceable>.
	    The specified encoding must be supported by the backend.
	   </para>
	  </listitem>
	 </varlistentry>
	 
	 <varlistentry>
	  <term>
	   DEFAULT
	  </term>
	  <listitem>
	   <para>
	    Sets the multi-byte client encoding.
	   </para>
	  </listitem>
	 </varlistentry>
	</variablelist>
       </para>

       <para>
	This is only enabled if multi-byte was specified to configure.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term>
       DateStyle
      </term>
      <listitem>
       <para>
	<variablelist>
	 <varlistentry>
	  <term>
113
	   ISO
114 115 116
	  </term>
	  <listitem>
	   <para>
117 118 119 120
	    use ISO 8601-style dates and times
	   </para>
	  </listitem>
	 </varlistentry>
121 122
	 <varlistentry>
	  <term>
123
	   SQL
124 125 126
	  </term>
	  <listitem>
	   <para>
127 128 129 130
	    use Oracle/Ingres-style dates and times
	   </para>
	  </listitem>
	 </varlistentry>
131 132
	 <varlistentry>
	  <term>
133
	   Postgres
134 135 136
	  </term>
	  <listitem>
	   <para>
137 138 139 140
	    use traditional <productname>Postgres</productname> format
	   </para>
	  </listitem>
	 </varlistentry>
141 142
	 <varlistentry>
	  <term>
143
	   European
144 145 146
	  </term>
	  <listitem>
	   <para>
147 148 149 150
	    use dd/mm/yyyy for numeric date representations.
	   </para>
	  </listitem>
	 </varlistentry>
151 152
	 <varlistentry>
	  <term>
153
	   NonEuropean
154 155 156
	  </term>
	  <listitem>
	   <para>
157 158 159 160
	    use mm/dd/yyyy for numeric date representations.
	   </para>
	  </listitem>
	 </varlistentry>
161 162
	 <varlistentry>
	  <term>
163
	   German
164 165 166
	  </term>
	  <listitem>
	   <para>
167 168 169 170
	    use dd.mm.yyyy for numeric date representations.
	   </para>
	  </listitem>
	 </varlistentry>
171 172
	 <varlistentry>
	  <term>
173
	   US
174 175 176
	  </term>
	  <listitem>
	   <para>
177 178 179 180
	    same as 'NonEuropean'
	   </para>
	  </listitem>
	 </varlistentry>
181 182
	 <varlistentry>
	  <term>
183
	   default
184 185 186
	  </term>
	  <listitem>
	   <para>
187 188 189 190 191 192
	    restores the default values ('US,Postgres')
	   </para>
	  </listitem>
	 </varlistentry>
	</variablelist>
       </para>
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260

       <para>
	Date format initialization my be done by:
	<simplelist>
	 <member>
	  Setting PGDATESTYLE environment variable.
	 </member>
	 <member>
	  Running postmaster using -oe parameter to set
	  dates to the 'European' convention.
	  Note that this affects only the some combinations of date styles; for example
	  the ISO style is not affected by this parameter.
	 </member>
	 <member>
	  Changing variables in 
	  <filename>src/backend/utils/init/globals.c</filename>.
	 </member>
	</simplelist>
       </para>
       <para>
	The variables in <filename>globals.c</filename> which can be changed are:
	<simplelist>
	 <member>
	  bool EuroDates = false | true
	 </member>
	 <member>
	  int  DateStyle = USE_ISO_DATES | USE_POSTGRES_DATES | USE_SQL_DATES | USE_GERMAN_DATES
	 </member>
	</simplelist>
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term>
       SERVER_ENCODING
      </term>
      <listitem>
       <para>
	Sets the multi-byte server encoding
	
	<variablelist>
	 <varlistentry>
	  <term>
	   <replaceable class="parameter">value</replaceable>
	  </term>
	  <listitem>
	   <para>
		Sets the multi-byte server encoding.
	   </para>
	  </listitem>
	 </varlistentry>
	 
	 <varlistentry>
	  <term>
	   DEFAULT
	  </term>
	  <listitem>
	   <para>
		Sets the multi-byte server encoding.
	   </para>
	  </listitem>
	 </varlistentry>
	</variablelist>
       </para>
       <para>
	This is only enabled if multi-byte was specified to configure.
       </para>
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
      </listitem>
     </varlistentry>

     <varlistentry>
      <term>
       TIMEZONE
      </term>
      <listitem>
       <para>
	The possible values for timezone depends on your operating
	system. For example on Linux /usr/lib/zoneinfo contains the
	database of timezones.
       </para>
       <para>
	Here are some valid values for timezone:
276
				
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 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
	<variablelist>
	 <varlistentry>
	  <term>
	   'PST8PDT'
	  </term>
	  <listitem>
	   <para>
	    set the timezone for California
	   </para>
	  </listitem>
	 </varlistentry>
	 <varlistentry>
	  <term>
	   'Portugal'
	  </term>
	  <listitem>
	   <para>
	    set time zone for Portugal.
	   </para>
	  </listitem>
	 </varlistentry>
	 <varlistentry>
	  <term>
	   'Europe/Rome'
	  </term>
	  <listitem>
	   <para>
	    set time zone for Italy.
	   </para>
	  </listitem>
	 </varlistentry>
	 <varlistentry>
	  <term>
	   DEFAULT
	  </term>
	  <listitem>
	   <para>
	    set time zone to your local timezone
	    (value of the TZ environment variable).
	   </para>
	  </listitem>
	 </varlistentry>
	</variablelist>
       </para>
       <para>
	If an invalid time zone is specified, the time zone
	becomes GMT (on most systems anyway).
       </para>
       <para>
	A frontend which uses libpq may be initialized by setting the PGTZ
	environment variable.
       </para>
       <para>
	The second syntax shown above, allows one to set the timezone
	with a syntax similar to SQL92 <command>SET TIME ZONE</command>.
	The LOCAL keyword is just an alternate form
	of DEFAULT for SQL92 compatibility.
       </para>
      </listitem>
     </varlistentry>
337 338 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 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386

     <varlistentry>
      <term>
       TRANSACTION ISOLATION LEVEL
      </term>
      <listitem>
       <para>
	Sets the isolation level for the current transaction.
	
	<variablelist>
	 <varlistentry>
	  <term>
	   READ COMMITTED
	  </term>
	  <listitem>
	   <para>
	    The current transaction reads only 
	    committed rows.  READ COMMITTED is the default.
	   </para>
	  </listitem>
	 </varlistentry>
	 
	 <varlistentry>
	  <term>
	   SERIALIZABLE
	  </term>
	  <listitem>
	   <para>
	    The current transaction will place a 
	    lock on every row read, so later reads in that transaction 
	    see the rows unmodified by other transactions.
	   </para>
	  </listitem>
	 </varlistentry>
	 
	 <varlistentry>
	  <term>
	   DEFAULT
	  </term>
	  <listitem>
	   <para>
	    Sets the isolation level for the current transaction to
	    <option>READ COMMITTED</option>.
	   </para>
	  </listitem>
	 </varlistentry>
	</variablelist>
       </para>
      </listitem>
     </varlistentry>
387 388
    </variablelist>
   </para>
389

390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
   <para>
    There are also several internal or optimization
    parameters which can be specified
    by the <command>SET</command> command:
    
    <variablelist>
     <varlistentry>
      <term>
       COST_HEAP
      </term>
      <listitem>
       <para>
	Sets the default cost of a heap scan for use by the optimizer.
	
	<variablelist>
	 <varlistentry>
	  <term>
	   <replaceable class="parameter">float4</replaceable>
	  </term>
	  <listitem>
	   <para>
	    Set the cost of a heap scan to the specified floating point value.
	   </para>
	  </listitem>
	 </varlistentry>
	 
	 <varlistentry>
	  <term>
	   DEFAULT
	  </term>
	  <listitem>
	   <para>
	    Sets the cost of a heap scan to the default value.
	   </para>
	  </listitem>
	 </varlistentry>
	</variablelist>
       </para>
       <para>
	The frontend may be initialized by setting the PGCOSTHEAP
	environment variable.
       </para>
      </listitem>
     </varlistentry>
434

435 436
     <varlistentry>
      <term>
437
       COST_INDEX
438 439 440
      </term>
      <listitem>
       <para>
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
	Sets the default cost of an index scan for use by the optimizer.

	<variablelist>     
	 <varlistentry>
	  <term>
	   <replaceable class="parameter">float4</replaceable>
	  </term>
	  <listitem>
	   <para>
	    Set the cost of an index scan to the specified floating point value.
	   </para>
	  </listitem>
	 </varlistentry>
	 
	 <varlistentry>
	  <term>
	   DEFAULT
	  </term>
	  <listitem>
	   <para>
	    Sets the cost of an index scan to the default value.
	   </para>
	  </listitem>
	 </varlistentry>
	</variablelist>
466
       </para>
467

468
       <para>
469 470
	The frontend may be initialized by setting the PGCOSTINDEX
	environment variable.
471 472 473
       </para>
      </listitem>
     </varlistentry>
474 475 476

     <varlistentry>
      <term>
477
       GEQO
478 479 480
      </term>
      <listitem>
       <para>
481 482
	Sets the threshold for using the genetic optimizer algorithm.
       
483 484 485
	<variablelist>
	 <varlistentry>
	  <term>
486
	   ON
487 488 489
	  </term>
	  <listitem>
	   <para>
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
	    enables the genetic optimizer algorithm
	    for statements with 6 or more tables.
	   </para>
	  </listitem>
	 </varlistentry>
	 <varlistentry>
	  <term>
	   ON=<replaceable class="parameter">#</replaceable>
	  </term>
	  <listitem>
	   <para>
	    Takes an integer argument to enable the genetic optimizer algorithm
	    for statements with <replaceable class="parameter">#</replaceable>
	    or more tables in the query.
	   </para>
	  </listitem>
	 </varlistentry>
	 <varlistentry>
	  <term>
	   OFF
	  </term>
	  <listitem>
	   <para>
	    disables the genetic optimizer algorithm.
514 515 516 517 518 519 520 521 522
	   </para>
	  </listitem>
	 </varlistentry>
	 <varlistentry>
	  <term>
	   DEFAULT
	  </term>
	  <listitem>
	   <para>
523
	    Equivalent to specifying <command>SET GEQO='ON'</command>
524 525 526 527 528
	   </para>
	  </listitem>
	 </varlistentry>
	</variablelist>
       </para>
529

530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
       <para>
	This algorithm is on by default, which used GEQO for
	statements of eleven or more tables.
	(See the chapter on GEQO in the Programmer's Guide
	for more information).
       </para>
       <para>
	The frontend may be initialized by setting PGGEQO
	environment variable.
       </para>
       <para>
	It may be useful when joining big relations with
	small ones. This algorithm is off by default.
	It's not used by GEQO anyway.
       </para>
      </listitem>
     </varlistentry>

548 549
     <varlistentry>
      <term>
550
       KSQO
551 552
      </term>
      <listitem>
553
       <para>
554 555 556 557
	<firstterm>Key Set Query Optimizer</firstterm> forces the query optimizer
	to optimize repetative OR clauses such as generated by
	<productname>MicroSoft Access</productname>:
       
558 559 560
	<variablelist>
	 <varlistentry>
	  <term>
561
	   ON
562 563 564
	  </term>
	  <listitem>
	   <para>
565 566 567 568 569 570 571 572 573 574 575 576
	    enables this optimization.
	   </para>
	  </listitem>
	 </varlistentry>
	
	 <varlistentry>
	  <term>
	   OFF
	  </term>
	  <listitem>
	   <para>
	    disables this optimization.
577 578 579 580 581 582 583 584 585 586
	   </para>
	  </listitem>
	 </varlistentry>
	 
	 <varlistentry>
	  <term>
	   DEFAULT
	  </term>
	  <listitem>
	   <para>
587
	    Equivalent to specifying <command>SET KSQO='OFF'</command>.
588 589 590 591 592
	   </para>
	  </listitem>
	 </varlistentry>
	</variablelist>
       </para>
593

594
       <para>
595 596 597
	It may be useful when joining big relations with
	small ones. This algorithm is off by default.
	It's not used by GEQO anyway.
598
       </para>
599 600 601 602 603 604
       <para>
	The frontend may be initialized by setting the PGKSQO
	environment variable.
       </para>
      </listitem>
     </varlistentry>
605 606 607

     <varlistentry>
      <term>
608
       QUERY_LIMIT
609 610 611
      </term>
      <listitem>
       <para>
612 613 614 615
	Sets the maximum number of rows returned by a query.
	By default, there is no limit to the number of rows
	returned by a query.
       
616 617 618
	<variablelist>
	 <varlistentry>
	  <term>
619
	   <replaceable class="parameter">#</replaceable>
620 621 622
	  </term>
	  <listitem>
	   <para>
623 624
	    Sets the maximum number of rows returned by a
	    query to <replaceable class="parameter">#</replaceable>.
625 626 627 628 629 630 631 632 633
	   </para>
	  </listitem>
	 </varlistentry>
	 <varlistentry>
	  <term>
	   DEFAULT
	  </term>
	  <listitem>
	   <para>
634
	    Sets the maximum number of rows returned by a query to be unlimited.
635 636 637 638 639
	   </para>
	  </listitem>
	 </varlistentry>
	</variablelist>
       </para>
640 641
      </listitem>
     </varlistentry>
642

643 644 645
    </variablelist>
   </para>
  </refsect2>
646

647 648 649 650 651
  <refsect2 id="R2-SQL-SET-2">
   <refsect2info>
    <date>1998-09-24</date>
   </refsect2info>
   <title>
652
    Outputs
653 654
   </title>
   <para>
655
    
656 657 658
    <variablelist>
     <varlistentry>
      <term>
659
       <returnvalue>SET VARIABLE</returnvalue>
660 661 662
      </term>
      <listitem>
       <para>
663 664 665 666 667
	Message returned if successfully.
       </para>
      </listitem>
     </varlistentry>
     
668 669 670 671 672 673 674 675 676
     <varlistentry>
      <term>
       <returnvalue>WARN:  Bad value for
	<replaceable class="parameter">variable</replaceable>
	(<replaceable class="parameter">value</replaceable>)</returnvalue>
      </term>
      <listitem>
       <para>
	If the command fails to set the specified variable.
677 678 679 680
       </para>
      </listitem>
     </varlistentry>
     
681
    </variablelist>
682
   </para>
683 684
  </refsect2>
 </refsynopsisdiv>
685
 
686 687 688 689 690
 <refsect1 id="R1-SQL-SET-1">
  <refsect1info>
   <date>1998-09-24</date>
  </refsect1info>
  <title>
691
   Description
692 693
  </title>
  <para>
694 695 696 697 698 699 700 701 702 703 704 705 706
   <command>SET</command> will modify configuration parameters for variable during
   a session.
  </para>
  <para>
   Current values can be obtained using <command>SHOW</command>, and values
   can be restored to the defaults using <command>RESET</command>.
   Parameters and values are case-insensitive. Note that the value
   field is always specified as a string, so is enclosed in
   single-quotes.
  </para>
  <para>
   <command>SET TIME ZONE</command> changes the session's
   default time zone offset.
707
   An SQL-session always begins with an initial default time zone
708 709 710 711 712
   offset.
   The <command>SET TIME ZONE</command> statement is used to change the default
   time zone offset for the current SQL session.
  </para>
  
713 714 715 716 717
  <refsect2 id="R2-SQL-SET-3">
   <refsect2info>
    <date>1998-09-24</date>
   </refsect2info>
   <title>
718
    Notes
719 720
   </title>
   <para>
721 722 723 724 725 726 727
    The <command>SET <replaceable class="parameter">variable</replaceable></command>
    statement is a <productname>Postgres</productname> language extension.
   </para>
   <para>
    Refer to <command>SHOW</command> and <command>RESET</command> to 
    display or reset the current values.
   </para>
728 729
  </refsect2>
 </refsect1>
730
 
731 732
 <refsect1 id="R1-SQL-SET-2">
  <title>
733
   Usage
734 735 736 737
  </title>
  <para>
  </para>
  <programlisting>
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770
   --Set the style of date to ISO:
   --
   SET DATESTYLE TO 'ISO';
  </programlisting>
  <programlisting> 
   --Enable GEQO for queries with 4 or more tables
   --
   SET GEQO ON=4;
  </programlisting>
  <programlisting> 
   --Set GEQO to default:
   --
   SET GEQO = DEFAULT;
  </programlisting>
  <programlisting> 
   --set the timezone for Berkeley, California:
   SET TIME ZONE 'PST8PDT';
   
   SELECT CURRENT_TIMESTAMP AS today;
   
   today
   ----------------------
   1998-03-31 07:41:21-08
  </programlisting>
  <programlisting> 
   --set the timezone for Italy:
   SET TIME ZONE 'Europe/Rome';
   
   SELECT CURRENT_TIMESTAMP AS today;
   
   today
   ----------------------
   1998-03-31 17:41:31+02
771
  </programlisting>
772
  
773
 </refsect1>
774

775 776
 <refsect1 id="R1-SQL-SET-3">
  <title>
777
   Compatibility
778 779 780
  </title>
  <para>
  </para>
781
  
782 783 784 785 786
  <refsect2 id="R2-SQL-SET-4">
   <refsect2info>
    <date>1998-09-24</date>
   </refsect2info>
   <title>
787
    SQL92
788 789
   </title>
   <para>
790 791 792 793 794 795 796 797 798 799 800 801 802 803
    There is no
    <command>SET <replaceable class="parameter">variable</replaceable></command>
    in <acronym>SQL92</acronym>.
    
    The <acronym>SQL92</acronym> syntax for <command>SET TIME ZONE</command>
    is slightly different,
    allowing only a single integer value for time zone specification:
    
    <programlisting>
     SET TIME ZONE { interval_value_expression | LOCAL }
    </programlisting>
   </para>
  </refsect2>
 </refsect1>
804
</refentry>
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
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
sgml-local-catalogs:"/usr/lib/sgml/CATALOG"
sgml-local-ecat-files:nil
End:
-->