SET 中文man页面

系统
SET 命令修改运行时配置参数。许多在 Section 16.4 ``Run-time Configuration'' 里面列出的运行时参数可以用 SET 在运行时设置。 (但是有些要求使用超级用户权限来修改,而其它有些则在服务器或者会话 开始之后不能修改。)请注意 SET 只影响当前会话使用的数值。

NAME

SET - 改变运行时参数

SYNOPSIS

SET [ SESSION | LOCAL ] name { TO | = } { value | 'value' | DEFAULT }
SET [ SESSION | LOCAL ] TIME ZONE { timezone | LOCAL | DEFAULT }

DESCRIPTION 描述

SET 命令修改运行时配置参数。许多在 Section 16.4 ``Run-time Configuration'' 里面列出的运行时参数可以用 SET 在运行时设置。 (但是有些要求使用超级用户权限来修改,而其它有些则在服务器或者会话 开始之后不能修改。)请注意 SET 只影响当前会话使用的数值。


 如果 SET 或者 SET SESSION 是在一个稍后退出的事务里发出的, 那么 SET 命令的效果将在事务回滚的之后小时。 (这个行为和PostgreSQL版本 7.3 之前的不同, 那个时候 SET 的效果在后面的错误之后不会回滚。) 一旦包围它的事务提交,那么其效果将持续到事务的结束,除非被另外一个 SET 覆盖。

SET LOCAL 的效果只持续到当前事务结束,不管是否提交。 一个特例是在一个事务里面的 SET 后面跟着一个 SET LOCAL:在事务结束之前只能看到 SET LOCAL 的数值,但是之后(如果事务提交),则是 SET 的值生效。  

PARAMETERS 选项

SESSION

 声明这个命令只对当前会话起作用。 (如果 SESSION 或 LOCAL 都没出现,那么这个是缺省。)
LOCAL

 声明该命令只在当前事务中有效。在 COMMIT 或者 ROLLBACK 之后,会话级别的设置将再次生效。 请注意如果在 BEGIN 块之外运行,那么 SET LOCAL  将表现出没有作用,因为事务将立即结束。
name

 可设置的运行时参数的名字。可用的参数在 Section 16.4 ``Run-time Configuration'' 和下面归档。
value

 参数的新值。值可以声明为字串常量,标识符,数字,或者逗号分隔的上面这些东西的列表。 DEFAULT 可以用于把这些参数设置为它们的缺省值。


 除了在 Section 16.4 ``Run-time Configuration'' 里面有文档记载的配置参数之外, 还有几个只能用 SET 命令设置,或者是有特殊的语法的参数:

NAMES
SET NAMES value 是 SET client_encoding TO value 的别名。
SEED

 为随机数生成器(函数 random)设置内部的种子。 允许的值是介于 0 和 1 之间的浮点数,然后它会被乘以 231-1。


 我们也可以通过调用函数 setseed 来设置种子:

SELECT setseed(value);

TIME ZONE
SET TIME ZONE value 是 for SET timezone TO value 的一个别名。 语法 SET TIME ZONE 允许为时区设置特殊的语法。 下面是有效值的例子:
'PST8PDT'

 加州伯克利的时区。
'Portugal'

 葡萄牙时区。
'Europe/Rome'

 意大利时区。
-7

 UTC 以西 7 小时的时区(等效于 PDT)。
INTERVAL '-08:00' HOUR TO MINUTE

 UTC 以西 8 小时的时区(等效于 PST)。
LOCAL
DEFAULT

 将时区设置为你的本地时区(服务器的操作系统缺省的那个)。


 参阅 Section 8.5 ``Date/Time Types'' 获取有关时区的更多细节。

NOTES 注意


 函数 set_config 提供了等效的功能。 参阅 Section 9.13 ``Miscellaneous Functions'' 。  

EXAMPLES 例子


 设置模式搜索路径:

SET search_path TO my_schema, public;

把日期时间风格设置为传统的 POSTGRES 风格, with ``day before month'' input convention:

SET datestyle TO postgres, dmy;


 把时区设置为加州伯克力, 使用双引号保存时区声明里大写字符的属性 (注意这里的日期/时间格式是 PostgreSQL):

SET TIME ZONE 'PST8PDT';
SELECT current_timestamp AS today;

             today
-------------------------------
 2003-04-29 15:02:01.218622-07

COMPATIBILITY 兼容性

SET TIME ZONE 扩展了在 SQL 标准里定义的语法。 标准只允许有一个数字时区偏移, 而 PostgreSQL 还允许完整更灵活的时区声明。 所有其它的 SET 特性都是 PostgreSQL 扩展。  

SEE ALSO 参见

RESET [reset(7)], SHOW [show(l)]

#p#

NAME

SET - change a run-time parameter

SYNOPSIS

SET [ SESSION | LOCAL ] name { TO | = } { value | 'value' | DEFAULT }
SET [ SESSION | LOCAL ] TIME ZONE { timezone | LOCAL | DEFAULT }

DESCRIPTION

The SET command changes run-time configuration parameters. Many of the run-time parameters listed in the section called ``Run-time Configuration'' in the documentation can be changed on-the-fly with SET. (But some require superuser privileges to change, and others cannot be changed after server or session start.) SET only affects the value used by the current session.

If SET or SET SESSION is issued within a transaction that is later aborted, the effects of the SET command disappear when the transaction is rolled back. (This behavior represents a change from PostgreSQL versions prior to 7.3, where the effects of SET 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 SET.

The effects of SET LOCAL last only till the end of the current transaction, whether committed or not. A special case is SET followed by SET LOCAL within a single transaction: the SET LOCAL value will be seen until the end of the transaction, but afterwards (if the transaction is committed) the SET value will take effect.  

PARAMETERS

SESSION
Specifies that the command takes effect for the current session. (This is the default if neither SESSION nor LOCAL appears.)
LOCAL
Specifies that the command takes effect for only the current transaction. After COMMIT or ROLLBACK, the session-level setting takes effect again. Note that SET LOCAL will appear to have no effect if it is executed outside a BEGIN block, since the transaction will end immediately.
name
Name of a settable run-time parameter. Available parameters are documented in the section called ``Run-time Configuration'' in the documentation and below.
value
New value of parameter. Values can be specified as string constants, identifiers, numbers, or comma-separated lists of these. DEFAULT can be used to specify resetting the parameter to its default value.

Besides the configuration parameters documented in the section called ``Run-time Configuration'' in the documentation, there are a few that can only be adjusted using the SET command or that have a special syntax:

NAMES
SET NAMES value is an alias for SET client_encoding TO value.
SEED
Sets the internal seed for the random number generator (the function random). Allowed values are floating-point numbers between 0 and 1, which are then multiplied by 231-1.

The seed can also be set by invoking the function setseed:

SELECT setseed(value);

TIME ZONE
SET TIME ZONE value is an alias for SET timezone TO value. The syntax SET TIME ZONE allows special syntax for the time zone specification. Here are examples of valid values (but note some are accepted only on some platforms):
'PST8PDT'
The time zone for Berkeley, California.
'Portugal'
The time zone for Portugal.
'Europe/Rome'
The time zone for Italy.
-7
The time zone 7 hours west from UTC (equivalent to PDT). Positive values are east from UTC.
INTERVAL '-08:00' HOUR TO MINUTE
The time zone 8 hours west from UTC (equivalent to PST).
LOCAL
DEFAULT
Set the time zone to your local time zone (the one that the server's operating system defaults to).

See the section called ``Date/Time Types'' in the documentation for more information about time zones.

NOTES

The function set_config provides equivalent functionality. See the section called ``Miscellaneous Functions'' in the documentation.  

EXAMPLES

Set the schema search path:

SET search_path TO my_schema, public;

Set the style of date to traditional POSTGRES with ``day before month'' input convention:

SET datestyle TO postgres, dmy;

Set the time zone for Berkeley, California, using quotes to preserve the uppercase spelling of the time zone name:

SET TIME ZONE 'PST8PDT';
SELECT current_timestamp AS today;

             today
-------------------------------
 2003-04-29 15:02:01.218622-07

COMPATIBILITY

SET TIME ZONE extends syntax defined in the SQL standard. The standard allows only numeric time zone offsets while PostgreSQL allows more flexible time-zone specifications. All other SET features are PostgreSQL extensions.  

SEE ALSO

RESET [reset(7)], SHOW [show(l)]

责任编辑:韩亚珊 来源: CMPP.net
相关推荐

2011-08-24 17:53:08

SET CONSTRA中文man

2011-08-24 18:02:22

SET TRANSAC中文man

2011-08-24 17:58:08

SET SESSION中文man

2011-08-24 16:48:36

man中文man

2011-08-15 10:21:09

man中文man

2011-08-11 16:11:49

at中文man

2011-08-25 10:21:56

man.conf中文man

2011-08-12 14:58:05

killall中文man

2011-07-15 16:58:36

ac中文man

2011-08-15 11:10:48

more中文man

2011-08-25 17:03:51

pclose中文man

2011-08-15 14:10:37

tar中文man

2011-08-16 10:42:30

rmmod中文man

2011-08-18 13:57:38

acct中文man

2011-08-23 17:49:36

zdump中文man

2011-08-15 15:10:49

wall中文man

2011-08-23 15:06:03

quotastats中文man

2011-08-15 17:35:50

ar中文man

2011-08-25 09:07:16

suffixes中文man

2011-08-18 15:21:37

autofs中文man
点赞
收藏

51CTO技术栈公众号