ok
Direktori : /opt/alt/postgresql11/usr/share/doc/alt-postgresql11-9.2.24/html/ |
Current File : //opt/alt/postgresql11/usr/share/doc/alt-postgresql11-9.2.24/html/sql-set.html |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >SET</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REV="MADE" HREF="mailto:pgsql-docs@postgresql.org"><LINK REL="HOME" TITLE="PostgreSQL 9.2.24 Documentation" HREF="index.html"><LINK REL="UP" TITLE="SQL Commands" HREF="sql-commands.html"><LINK REL="PREVIOUS" TITLE="SELECT INTO" HREF="sql-selectinto.html"><LINK REL="NEXT" TITLE="SET CONSTRAINTS" HREF="sql-set-constraints.html"><LINK REL="STYLESHEET" TYPE="text/css" HREF="stylesheet.css"><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"><META NAME="creation" CONTENT="2017-11-06T22:43:11"></HEAD ><BODY CLASS="REFENTRY" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="5" ALIGN="center" VALIGN="bottom" ><A HREF="index.html" >PostgreSQL 9.2.24 Documentation</A ></TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A TITLE="SELECT INTO" HREF="sql-selectinto.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A HREF="sql-commands.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="60%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="20%" ALIGN="right" VALIGN="top" ><A TITLE="SET CONSTRAINTS" HREF="sql-set-constraints.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="SQL-SET" ></A >SET</H1 ><DIV CLASS="REFNAMEDIV" ><A NAME="AEN78675" ></A ><H2 >Name</H2 >SET -- change a run-time parameter</DIV ><DIV CLASS="REFSYNOPSISDIV" ><A NAME="AEN78680" ></A ><H2 >Synopsis</H2 ><PRE CLASS="SYNOPSIS" >SET [ SESSION | LOCAL ] <TT CLASS="REPLACEABLE" ><I >configuration_parameter</I ></TT > { TO | = } { <TT CLASS="REPLACEABLE" ><I >value</I ></TT > | '<TT CLASS="REPLACEABLE" ><I >value</I ></TT >' | DEFAULT } SET [ SESSION | LOCAL ] TIME ZONE { <TT CLASS="REPLACEABLE" ><I >timezone</I ></TT > | LOCAL | DEFAULT }</PRE ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN78686" ></A ><H2 >Description</H2 ><P > The <TT CLASS="COMMAND" >SET</TT > command changes run-time configuration parameters. Many of the run-time parameters listed in <A HREF="runtime-config.html" >Chapter 18</A > can be changed on-the-fly with <TT CLASS="COMMAND" >SET</TT >. (But some require superuser privileges to change, and others cannot be changed after server or session start.) <TT CLASS="COMMAND" >SET</TT > only affects the value used by the current session. </P ><P > If <TT CLASS="COMMAND" >SET</TT > (or equivalently <TT CLASS="COMMAND" >SET SESSION</TT >) is issued within a transaction that is later aborted, the effects of the <TT CLASS="COMMAND" >SET</TT > command disappear when the transaction is rolled back. Once the surrounding transaction is committed, the effects will persist until the end of the session, unless overridden by another <TT CLASS="COMMAND" >SET</TT >. </P ><P > The effects of <TT CLASS="COMMAND" >SET LOCAL</TT > last only till the end of the current transaction, whether committed or not. A special case is <TT CLASS="COMMAND" >SET</TT > followed by <TT CLASS="COMMAND" >SET LOCAL</TT > within a single transaction: the <TT CLASS="COMMAND" >SET LOCAL</TT > value will be seen until the end of the transaction, but afterwards (if the transaction is committed) the <TT CLASS="COMMAND" >SET</TT > value will take effect. </P ><P > The effects of <TT CLASS="COMMAND" >SET</TT > or <TT CLASS="COMMAND" >SET LOCAL</TT > are also canceled by rolling back to a savepoint that is earlier than the command. </P ><P > If <TT CLASS="COMMAND" >SET LOCAL</TT > is used within a function that has a <TT CLASS="LITERAL" >SET</TT > option for the same variable (see <A HREF="sql-createfunction.html" >CREATE FUNCTION</A >), the effects of the <TT CLASS="COMMAND" >SET LOCAL</TT > command disappear at function exit; that is, the value in effect when the function was called is restored anyway. This allows <TT CLASS="COMMAND" >SET LOCAL</TT > to be used for dynamic or repeated changes of a parameter within a function, while still having the convenience of using the <TT CLASS="LITERAL" >SET</TT > option to save and restore the caller's value. However, a regular <TT CLASS="COMMAND" >SET</TT > command overrides any surrounding function's <TT CLASS="LITERAL" >SET</TT > option; its effects will persist unless rolled back. </P ><DIV CLASS="NOTE" ><BLOCKQUOTE CLASS="NOTE" ><P ><B >Note: </B > In <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > versions 8.0 through 8.2, the effects of a <TT CLASS="COMMAND" >SET LOCAL</TT > would be canceled by releasing an earlier savepoint, or by successful exit from a <SPAN CLASS="APPLICATION" >PL/pgSQL</SPAN > exception block. This behavior has been changed because it was deemed unintuitive. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN78721" ></A ><H2 >Parameters</H2 ><P ></P ><DIV CLASS="VARIABLELIST" ><DL ><DT ><TT CLASS="LITERAL" >SESSION</TT ></DT ><DD ><P > Specifies that the command takes effect for the current session. (This is the default if neither <TT CLASS="LITERAL" >SESSION</TT > nor <TT CLASS="LITERAL" >LOCAL</TT > appears.) </P ></DD ><DT ><TT CLASS="LITERAL" >LOCAL</TT ></DT ><DD ><P > Specifies that the command takes effect for only the current transaction. After <TT CLASS="COMMAND" >COMMIT</TT > or <TT CLASS="COMMAND" >ROLLBACK</TT >, the session-level setting takes effect again. Note that <TT CLASS="COMMAND" >SET LOCAL</TT > will appear to have no effect if it is executed outside a <TT CLASS="COMMAND" >BEGIN</TT > block, since the transaction will end immediately. </P ></DD ><DT ><TT CLASS="REPLACEABLE" ><I >configuration_parameter</I ></TT ></DT ><DD ><P > Name of a settable run-time parameter. Available parameters are documented in <A HREF="runtime-config.html" >Chapter 18</A > and below. </P ></DD ><DT ><TT CLASS="REPLACEABLE" ><I >value</I ></TT ></DT ><DD ><P > New value of parameter. Values can be specified as string constants, identifiers, numbers, or comma-separated lists of these, as appropriate for the particular parameter. <TT CLASS="LITERAL" >DEFAULT</TT > can be written to specify resetting the parameter to its default value (that is, whatever value it would have had if no <TT CLASS="COMMAND" >SET</TT > had been executed in the current session). </P ></DD ></DL ></DIV ><P > Besides the configuration parameters documented in <A HREF="runtime-config.html" >Chapter 18</A >, there are a few that can only be adjusted using the <TT CLASS="COMMAND" >SET</TT > command or that have a special syntax: <P ></P ></P><DIV CLASS="VARIABLELIST" ><DL ><DT ><TT CLASS="LITERAL" >SCHEMA</TT ></DT ><DD ><P ><TT CLASS="LITERAL" >SET SCHEMA '<TT CLASS="REPLACEABLE" ><I >value</I ></TT >'</TT > is an alias for <TT CLASS="LITERAL" >SET search_path TO <TT CLASS="REPLACEABLE" ><I >value</I ></TT ></TT >. Only one schema can be specified using this syntax. </P ></DD ><DT ><TT CLASS="LITERAL" >NAMES</TT ></DT ><DD ><P ><TT CLASS="LITERAL" >SET NAMES <TT CLASS="REPLACEABLE" ><I >value</I ></TT ></TT > is an alias for <TT CLASS="LITERAL" >SET client_encoding TO <TT CLASS="REPLACEABLE" ><I >value</I ></TT ></TT >. </P ></DD ><DT ><TT CLASS="LITERAL" >SEED</TT ></DT ><DD ><P > Sets the internal seed for the random number generator (the function <CODE CLASS="FUNCTION" >random</CODE >). Allowed values are floating-point numbers between -1 and 1, which are then multiplied by 2<SUP >31</SUP >-1. </P ><P > The seed can also be set by invoking the function <CODE CLASS="FUNCTION" >setseed</CODE >: </P><PRE CLASS="PROGRAMLISTING" >SELECT setseed(<TT CLASS="REPLACEABLE" ><I >value</I ></TT >);</PRE ><P></P ></DD ><DT ><TT CLASS="LITERAL" >TIME ZONE</TT ></DT ><DD ><P ><TT CLASS="LITERAL" >SET TIME ZONE <TT CLASS="REPLACEABLE" ><I >value</I ></TT ></TT > is an alias for <TT CLASS="LITERAL" >SET timezone TO <TT CLASS="REPLACEABLE" ><I >value</I ></TT ></TT >. The syntax <TT CLASS="LITERAL" >SET TIME ZONE</TT > allows special syntax for the time zone specification. Here are examples of valid values: <P ></P ></P><DIV CLASS="VARIABLELIST" ><DL ><DT ><TT CLASS="LITERAL" >'PST8PDT'</TT ></DT ><DD ><P > The time zone for Berkeley, California. </P ></DD ><DT ><TT CLASS="LITERAL" >'Europe/Rome'</TT ></DT ><DD ><P > The time zone for Italy. </P ></DD ><DT ><TT CLASS="LITERAL" >-7</TT ></DT ><DD ><P > The time zone 7 hours west from UTC (equivalent to PDT). Positive values are east from UTC. </P ></DD ><DT ><TT CLASS="LITERAL" >INTERVAL '-08:00' HOUR TO MINUTE</TT ></DT ><DD ><P > The time zone 8 hours west from UTC (equivalent to PST). </P ></DD ><DT ><TT CLASS="LITERAL" >LOCAL</TT ><BR><TT CLASS="LITERAL" >DEFAULT</TT ></DT ><DD ><P > Set the time zone to your local time zone (that is, the server's default value of <TT CLASS="VARNAME" >timezone</TT >). </P ></DD ></DL ></DIV ><P> See <A HREF="datatype-datetime.html#DATATYPE-TIMEZONES" >Section 8.5.3</A > for more information about time zones. </P ></DD ></DL ></DIV ><P> </P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN78826" ></A ><H2 >Notes</H2 ><P > The function <CODE CLASS="FUNCTION" >set_config</CODE > provides equivalent functionality; see <A HREF="functions-admin.html" >Section 9.26</A >. Also, it is possible to UPDATE the <A HREF="view-pg-settings.html" ><TT CLASS="STRUCTNAME" >pg_settings</TT ></A > system view to perform the equivalent of <TT CLASS="COMMAND" >SET</TT >. </P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN78834" ></A ><H2 >Examples</H2 ><P > Set the schema search path: </P><PRE CLASS="PROGRAMLISTING" >SET search_path TO my_schema, public;</PRE ><P> </P ><P > Set the style of date to traditional <SPAN CLASS="PRODUCTNAME" >POSTGRES</SPAN > with <SPAN CLASS="QUOTE" >"day before month"</SPAN > input convention: </P><PRE CLASS="SCREEN" >SET datestyle TO postgres, dmy;</PRE ><P> </P ><P > Set the time zone for Berkeley, California: </P><PRE CLASS="SCREEN" >SET TIME ZONE 'PST8PDT';</PRE ><P> </P ><P > Set the time zone for Italy: </P><PRE CLASS="SCREEN" >SET TIME ZONE 'Europe/Rome';</PRE ><P></P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN78846" ></A ><H2 >Compatibility</H2 ><P > <TT CLASS="LITERAL" >SET TIME ZONE</TT > extends syntax defined in the SQL standard. The standard allows only numeric time zone offsets while <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > allows more flexible time-zone specifications. All other <TT CLASS="LITERAL" >SET</TT > features are <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > extensions. </P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN78853" ></A ><H2 >See Also</H2 ><A HREF="sql-reset.html" >RESET</A >, <A HREF="sql-show.html" >SHOW</A ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="sql-selectinto.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="sql-set-constraints.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >SELECT INTO</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="sql-commands.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >SET CONSTRAINTS</TD ></TR ></TABLE ></DIV ></BODY ></HTML >