バージョンごとのドキュメント一覧

SET

SET <refpurpose>change a run-time parameter</refpurpose> — 実行時パラメータを変更する

概要

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

説明

<title>Description</title>

The <command>SET</command> command changes run-time configuration parameters. Many of the run-time parameters listed in <xref linkend="runtime-config"/> can be changed on-the-fly with <command>SET</command>. (Some parameters can only be changed by superusers and users who have been granted <literal>SET</literal> privilege on that parameter. There are also parameters that cannot be changed after server or session start.) <command>SET</command> only affects the value used by the current session. SETコマンドは実行時設定パラメータを変更します。 第20章に列挙されている実行時パラメータの多くは稼働中にSETコマンドで変更できます。 (パラメータの中には、スーパーユーザとそのパラメータのSET権限を付与されたユーザだけが変更できるものもあります。 また、サーバあるいはセッションの始動後は変更できないパラメータもあります。) SETは現行セッションで使用される値にのみ影響することに注意してください。

If <command>SET</command> (or equivalently <command>SET SESSION</command>) is issued within a transaction that is later aborted, the effects of the <command>SET</command> 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 <command>SET</command>. SET(またはSET SESSIONも同じ)が発行された後にトランザクションがアボートされると、トランザクションがロールバックした時点でSETコマンドの効力は失われます。 一度トランザクションがコミットされると、別のSETコマンドで上書きされない限り、セッションが終了するまでその効果が持続します。

The effects of <command>SET LOCAL</command> last only till the end of the current transaction, whether committed or not. A special case is <command>SET</command> followed by <command>SET LOCAL</command> within a single transaction: the <command>SET LOCAL</command> value will be seen until the end of the transaction, but afterwards (if the transaction is committed) the <command>SET</command> value will take effect. SET LOCALの効果は、コミットのされたかどうかにかかわらず現在のトランザクションが終了するまでしか持続しません。 1つのトランザクション内でSETの後にSET LOCALが続く特殊な例を考えてみましょう。 この場合、トランザクションが終了するまではSET LOCAL値が有効ですが、その後(トランザクションがコミットされたとして)SET値が有効になります。

The effects of <command>SET</command> or <command>SET LOCAL</command> are also canceled by rolling back to a savepoint that is earlier than the command. SETもしくはSET LOCALの効果は、このコマンドより以前のセーブポイントまでロールバックした場合は取り消されます。

If <command>SET LOCAL</command> is used within a function that has a <literal>SET</literal> option for the same variable (see <xref linkend="sql-createfunction"/>), the effects of the <command>SET LOCAL</command> command disappear at function exit; that is, the value in effect when the function was called is restored anyway. This allows <command>SET LOCAL</command> to be used for dynamic or repeated changes of a parameter within a function, while still having the convenience of using the <literal>SET</literal> option to save and restore the caller's value. However, a regular <command>SET</command> command overrides any surrounding function's <literal>SET</literal> option; its effects will persist unless rolled back. SET LOCALを同じ変数に対するSETオプション(CREATE FUNCTIONを参照)を持つ関数内で使用する場合、SET LOCALコマンドの効果は関数終了時に消滅します。 つまり、関数が呼び出された時に有効だった値にとにかく戻されます。 これによりSET LOCALは、呼び出し元の値を保管し元に戻すというSETオプションを使用する利点を持ちつつ、関数内で動的または繰り返し変更されるパラメータ用に使用できます。 しかし、通常のSETコマンドでは上位の関数のSETオプションを上書きしてしまい、その効果はロールバックしない限り永続します。

注記

In <productname>PostgreSQL</productname> versions 8.0 through 8.2, the effects of a <command>SET LOCAL</command> would be canceled by releasing an earlier savepoint, or by successful exit from a <application>PL/pgSQL</application> exception block. This behavior has been changed because it was deemed unintuitive. PostgreSQLバージョン8.0から8.2まででは、SET LOCALの効果は、より以前のセーブポイントを解放すること、または、PL/pgSQL例外ブロックから正常終了することで取り消されました。 直観的ではないようですので、この動作は変更されました。

パラメータ

<title>Parameters</title>
SESSION

Specifies that the command takes effect for the current session. (This is the default if neither <literal>SESSION</literal> nor <literal>LOCAL</literal> appears.) コマンドの有効範囲が現行セッションであることを指定します。 (SESSIONLOCALも指定されていない場合は、これがデフォルトです。)

LOCAL

Specifies that the command takes effect for only the current transaction. After <command>COMMIT</command> or <command>ROLLBACK</command>, the session-level setting takes effect again. Issuing this outside of a transaction block emits a warning and otherwise has no effect. コマンドの有効範囲が現行のトランザクションのみであることを指定します。 COMMITまたはROLLBACKの後は、再びセッションレベルの設定が有効になります。 これをトランザクションブロックの外側で実行すると、警告が発生しますが、それ以外には何の効果もありません。

configuration_parameter

Name of a settable run-time parameter. Available parameters are documented in <xref linkend="runtime-config"/> and below. 設定可能な実行時パラメータ名です。 利用可能なパラメータは、第20章と以下に示します。

value

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. <literal>DEFAULT</literal> can be written to specify resetting the parameter to its default value (that is, whatever value it would have had if no <command>SET</command> had been executed in the current session). パラメータの新しい値です。 値として、文字列定数、識別子、数字、あるいはこれらをカンマで区切ったリストを対象のパラメータで適切となるように、指定することができます。 DEFAULTと記述することで、パラメータをデフォルト値(つまり、現在のセッションでSETが実行されなかった時に設定される値)に再設定することができます。

Besides the configuration parameters documented in <xref linkend="runtime-config"/>, there are a few that can only be adjusted using the <command>SET</command> command or that have a special syntax: 第20章に記載された設定パラメータの他に、SETコマンドを使用してのみ調整できるパラメータや特殊な構文を持つパラメータがいくつかあります。

SCHEMA
<para><literal>SET SCHEMA '<replaceable>value</replaceable>'</literal> is an alias for <literal>SET search_path TO <replaceable>value</replaceable></literal>. Only one schema can be specified using this syntax.

SET SCHEMA 'value'SET search_path TO valueの別名です。 この構文を使用する場合は1つのスキーマのみを指定することができます。

NAMES
<para><literal>SET NAMES <replaceable>value</replaceable></literal> is an alias for <literal>SET client_encoding TO <replaceable>value</replaceable></literal>.

SET NAMES valueは、SET client_encoding TO valueの別名です。

SEED

Sets the internal seed for the random number generator (the function <function>random</function>). Allowed values are floating-point numbers between -1 and 1 inclusive. 乱数ジェネレータ(random関数)用の内部シードを設定します。 (-1と1も含めて)-1から1までの浮動小数点数を値として設定できます。

The seed can also be set by invoking the function <function>setseed</function>: シードはsetseed関数を呼び出すことでも設定可能です。

SELECT setseed(value);
TIME ZONE
<para><literal>SET TIME ZONE '<replaceable>value</replaceable>'</literal> is an alias for <literal>SET timezone TO '<replaceable>value</replaceable>'</literal>. The syntax <literal>SET TIME ZONE</literal> allows special syntax for the time zone specification. Here are examples of valid values:

SET TIME ZONE 'value'SET timezone TO 'value'の別名です。 SET TIME ZONE構文では、時間帯の指定に特殊な構文を使用できます。 有効な値の例を以下に示します。

'PST8PDT'

The time zone for Berkeley, California. カリフォルニア州バークレイ用の時間帯です。

'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. UTCから西に7時間分ずらした時間帯です(PDTと同じです)。 正の値はUTCから東方向です。

INTERVAL '-08:00' HOUR TO MINUTE

The time zone 8 hours west from UTC (equivalent to PST). UTCから西に8時間分ずらした時間帯です(PSTと同じです)。

LOCAL
DEFAULT

Set the time zone to your local time zone (that is, the server's default value of <varname>timezone</varname>). 時間帯をユーザのローカルな時間帯(サーバのデフォルトのtimezone値)に設定します。

Timezone settings given as numbers or intervals are internally translated to POSIX timezone syntax. For example, after <literal>SET TIME ZONE -7</literal>, <command>SHOW TIME ZONE</command> would report <literal>&lt;-07&gt;+07</literal>. 時間帯を数字あるいは時間で指定した時は、内部的にPOSIXの時間帯構文として解釈されます。 例えば、SET TIME ZONE -7とした後、SHOW TIME ZONEを実行すると、その結果は<-07>+07となります。

Time zone abbreviations are not supported by <command>SET</command>; see <xref linkend="datatype-timezones"/> for more information about time zones. 時間帯の省略形はSETではサポートされていません。時間帯に関する詳細は8.5.3を参照してください。

注釈

<title>Notes</title>

The function <function>set_config</function> provides equivalent functionality; see <xref linkend="functions-admin-set"/>. Also, it is possible to UPDATE the <link linkend="view-pg-settings"><structname>pg_settings</structname></link> system view to perform the equivalent of <command>SET</command>. set_config関数は等価な機能を提供します。 9.27.1を参照してください。 また、pg_settingsシステムビューを更新することで、SETと同じことを実行することができます。

<title>Examples</title>

Set the schema search path: スキーマの検索パスを設定します。

SET search_path TO my_schema, public;

Set the style of date to traditional <productname>POSTGRES</productname> with <quote>day before month</quote> input convention: 日付のスタイルを、伝統的なPOSTGRES入力方式に設定し、さらにday before month(月の前に日)を使います。

SET datestyle TO postgres, dmy;

Set the time zone for Berkeley, California: 時間帯をカリフォルニア州バークレイに設定します。

SET TIME ZONE 'PST8PDT';

Set the time zone for Italy: 時間帯をイタリアに設定します。

SET TIME ZONE 'Europe/Rome';

互換性

<title>Compatibility</title>

<literal>SET TIME ZONE</literal> extends syntax defined in the SQL standard. The standard allows only numeric time zone offsets while <productname>PostgreSQL</productname> allows more flexible time-zone specifications. All other <literal>SET</literal> features are <productname>PostgreSQL</productname> extensions. SET TIME ZONEは標準SQLで定義された構文を拡張したものです。 標準では数値による時間帯オフセットしか使用できないのに対し、PostgreSQLでは、より柔軟に時間帯を指定することができます。 SETが持つその他の機能は、全てPostgreSQLの拡張です。

関連項目

<title>See Also</title> RESET, SHOW