gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

153 行
13KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>SET</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="sql-selectinto.html" title="SELECT INTO" /><link rel="next" href="sql-set-constraints.html" title="SET CONSTRAINTS" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">SET</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-selectinto.html" title="SELECT INTO">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-set-constraints.html" title="SET CONSTRAINTS">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="SQL-SET"><div class="titlepage"></div><a id="id-1.9.3.173.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">SET</span></h2><p>SET — change a run-time parameter</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
  3. SET [ SESSION | LOCAL ] <em class="replaceable"><code>configuration_parameter</code></em> { TO | = } { <em class="replaceable"><code>value</code></em> | '<em class="replaceable"><code>value</code></em>' | DEFAULT }
  4. SET [ SESSION | LOCAL ] TIME ZONE { <em class="replaceable"><code>timezone</code></em> | LOCAL | DEFAULT }
  5. </pre></div><div class="refsect1" id="id-1.9.3.173.5"><h2>Description</h2><p>
  6. The <code class="command">SET</code> command changes run-time configuration
  7. parameters. Many of the run-time parameters listed in
  8. <a class="xref" href="runtime-config.html" title="Chapter 19. Server Configuration">Chapter 19</a> can be changed on-the-fly with
  9. <code class="command">SET</code>.
  10. (But some require superuser privileges to change, and others cannot
  11. be changed after server or session start.)
  12. <code class="command">SET</code> only affects the value used by the current
  13. session.
  14. </p><p>
  15. If <code class="command">SET</code> (or equivalently <code class="command">SET SESSION</code>)
  16. is issued within a transaction that is later aborted, the effects of the
  17. <code class="command">SET</code> command disappear when the transaction is rolled
  18. back. Once the surrounding transaction is committed, the effects
  19. will persist until the end of the session, unless overridden by another
  20. <code class="command">SET</code>.
  21. </p><p>
  22. The effects of <code class="command">SET LOCAL</code> last only till the end of
  23. the current transaction, whether committed or not. A special case is
  24. <code class="command">SET</code> followed by <code class="command">SET LOCAL</code> within
  25. a single transaction: the <code class="command">SET LOCAL</code> value will be
  26. seen until the end of the transaction, but afterwards (if the transaction
  27. is committed) the <code class="command">SET</code> value will take effect.
  28. </p><p>
  29. The effects of <code class="command">SET</code> or <code class="command">SET LOCAL</code> are
  30. also canceled by rolling back to a savepoint that is earlier than the
  31. command.
  32. </p><p>
  33. If <code class="command">SET LOCAL</code> is used within a function that has a
  34. <code class="literal">SET</code> option for the same variable (see
  35. <a class="xref" href="sql-createfunction.html" title="CREATE FUNCTION"><span class="refentrytitle">CREATE FUNCTION</span></a>),
  36. the effects of the <code class="command">SET LOCAL</code> command disappear at
  37. function exit; that is, the value in effect when the function was called is
  38. restored anyway. This allows <code class="command">SET LOCAL</code> to be used for
  39. dynamic or repeated changes of a parameter within a function, while still
  40. having the convenience of using the <code class="literal">SET</code> option to save and
  41. restore the caller's value. However, a regular <code class="command">SET</code> command
  42. overrides any surrounding function's <code class="literal">SET</code> option; its effects
  43. will persist unless rolled back.
  44. </p><div class="note"><h3 class="title">Note</h3><p>
  45. In <span class="productname">PostgreSQL</span> versions 8.0 through 8.2,
  46. the effects of a <code class="command">SET LOCAL</code> would be canceled by
  47. releasing an earlier savepoint, or by successful exit from a
  48. <span class="application">PL/pgSQL</span> exception block. This behavior
  49. has been changed because it was deemed unintuitive.
  50. </p></div></div><div class="refsect1" id="id-1.9.3.173.6"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">SESSION</code></span></dt><dd><p>
  51. Specifies that the command takes effect for the current session.
  52. (This is the default if neither <code class="literal">SESSION</code> nor
  53. <code class="literal">LOCAL</code> appears.)
  54. </p></dd><dt><span class="term"><code class="literal">LOCAL</code></span></dt><dd><p>
  55. Specifies that the command takes effect for only the current
  56. transaction. After <code class="command">COMMIT</code> or <code class="command">ROLLBACK</code>,
  57. the session-level setting takes effect again. Issuing this
  58. outside of a transaction block emits a warning and otherwise has
  59. no effect.
  60. </p></dd><dt><span class="term"><em class="replaceable"><code>configuration_parameter</code></em></span></dt><dd><p>
  61. Name of a settable run-time parameter. Available parameters are
  62. documented in <a class="xref" href="runtime-config.html" title="Chapter 19. Server Configuration">Chapter 19</a> and below.
  63. </p></dd><dt><span class="term"><em class="replaceable"><code>value</code></em></span></dt><dd><p>
  64. New value of parameter. Values can be specified as string
  65. constants, identifiers, numbers, or comma-separated lists of
  66. these, as appropriate for the particular parameter.
  67. <code class="literal">DEFAULT</code> can be written to specify
  68. resetting the parameter to its default value (that is, whatever
  69. value it would have had if no <code class="command">SET</code> had been executed
  70. in the current session).
  71. </p></dd></dl></div><p>
  72. Besides the configuration parameters documented in <a class="xref" href="runtime-config.html" title="Chapter 19. Server Configuration">Chapter 19</a>, there are a few that can only be
  73. adjusted using the <code class="command">SET</code> command or that have a
  74. special syntax:
  75. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">SCHEMA</code></span></dt><dd><p><code class="literal">SET SCHEMA '<em class="replaceable"><code>value</code></em>'</code> is an alias for
  76. <code class="literal">SET search_path TO <em class="replaceable"><code>value</code></em></code>. Only one
  77. schema can be specified using this syntax.
  78. </p></dd><dt><span class="term"><code class="literal">NAMES</code></span></dt><dd><p><code class="literal">SET NAMES <em class="replaceable"><code>value</code></em></code> is an alias for
  79. <code class="literal">SET client_encoding TO <em class="replaceable"><code>value</code></em></code>.
  80. </p></dd><dt><span class="term"><code class="literal">SEED</code></span></dt><dd><p>
  81. Sets the internal seed for the random number generator (the
  82. function <code class="function">random</code>). Allowed values are
  83. floating-point numbers between -1 and 1, which are then
  84. multiplied by 2<sup>31</sup>-1.
  85. </p><p>
  86. The seed can also be set by invoking the function
  87. <code class="function">setseed</code>:
  88. </p><pre class="programlisting">
  89. SELECT setseed(<em class="replaceable"><code>value</code></em>);
  90. </pre></dd><dt><span class="term"><code class="literal">TIME ZONE</code></span></dt><dd><p><code class="literal">SET TIME ZONE <em class="replaceable"><code>value</code></em></code> is an alias
  91. for <code class="literal">SET timezone TO <em class="replaceable"><code>value</code></em></code>. The
  92. syntax <code class="literal">SET TIME ZONE</code> allows special syntax
  93. for the time zone specification. Here are examples of valid
  94. values:
  95. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">'PST8PDT'</code></span></dt><dd><p>
  96. The time zone for Berkeley, California.
  97. </p></dd><dt><span class="term"><code class="literal">'Europe/Rome'</code></span></dt><dd><p>
  98. The time zone for Italy.
  99. </p></dd><dt><span class="term"><code class="literal">-7</code></span></dt><dd><p>
  100. The time zone 7 hours west from UTC (equivalent
  101. to PDT). Positive values are east from UTC.
  102. </p></dd><dt><span class="term"><code class="literal">INTERVAL '-08:00' HOUR TO MINUTE</code></span></dt><dd><p>
  103. The time zone 8 hours west from UTC (equivalent
  104. to PST).
  105. </p></dd><dt><span class="term"><code class="literal">LOCAL</code><br /></span><span class="term"><code class="literal">DEFAULT</code></span></dt><dd><p>
  106. Set the time zone to your local time zone (that is, the
  107. server's default value of <code class="varname">timezone</code>).
  108. </p></dd></dl></div><p>
  109. </p><p>
  110. Timezone settings given as numbers or intervals are internally
  111. translated to POSIX timezone syntax. For example, after
  112. <code class="literal">SET TIME ZONE -7</code>, <code class="command">SHOW TIME ZONE</code> would
  113. report <code class="literal">&lt;-07&gt;+07</code>.
  114. </p><p>
  115. See <a class="xref" href="datatype-datetime.html#DATATYPE-TIMEZONES" title="8.5.3. Time Zones">Section 8.5.3</a> for more information
  116. about time zones.
  117. </p></dd></dl></div><p>
  118. </p></div><div class="refsect1" id="id-1.9.3.173.7"><h2>Notes</h2><p>
  119. The function <code class="function">set_config</code> provides equivalent
  120. functionality; see <a class="xref" href="functions-admin.html" title="9.26. System Administration Functions">Section 9.26</a>.
  121. Also, it is possible to UPDATE the
  122. <a class="link" href="view-pg-settings.html" title="51.86. pg_settings"><code class="structname">pg_settings</code></a>
  123. system view to perform the equivalent of <code class="command">SET</code>.
  124. </p></div><div class="refsect1" id="id-1.9.3.173.8"><h2>Examples</h2><p>
  125. Set the schema search path:
  126. </p><pre class="programlisting">
  127. SET search_path TO my_schema, public;
  128. </pre><p>
  129. </p><p>
  130. Set the style of date to traditional
  131. <span class="productname">POSTGRES</span> with <span class="quote">“<span class="quote">day before month</span>”</span>
  132. input convention:
  133. </p><pre class="screen">
  134. SET datestyle TO postgres, dmy;
  135. </pre><p>
  136. </p><p>
  137. Set the time zone for Berkeley, California:
  138. </p><pre class="screen">
  139. SET TIME ZONE 'PST8PDT';
  140. </pre><p>
  141. </p><p>
  142. Set the time zone for Italy:
  143. </p><pre class="screen">
  144. SET TIME ZONE 'Europe/Rome';
  145. </pre></div><div class="refsect1" id="id-1.9.3.173.9"><h2>Compatibility</h2><p>
  146. <code class="literal">SET TIME ZONE</code> extends syntax defined in the SQL
  147. standard. The standard allows only numeric time zone offsets while
  148. <span class="productname">PostgreSQL</span> allows more flexible
  149. time-zone specifications. All other <code class="literal">SET</code>
  150. features are <span class="productname">PostgreSQL</span> extensions.
  151. </p></div><div class="refsect1" id="id-1.9.3.173.10"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-reset.html" title="RESET"><span class="refentrytitle">RESET</span></a>, <a class="xref" href="sql-show.html" title="SHOW"><span class="refentrytitle">SHOW</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sql-selectinto.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-set-constraints.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">SELECT INTO </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> SET CONSTRAINTS</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1