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

ALTER FOREIGN TABLE

ALTER FOREIGN TABLE <refpurpose>change the definition of a foreign table</refpurpose> — 外部テーブルの定義を変更する

概要

ALTER FOREIGN TABLE [ IF EXISTS ] [ ONLY ] name [ * ]
    action [, ... ]
ALTER FOREIGN TABLE [ IF EXISTS ] [ ONLY ] name [ * ]
    RENAME [ COLUMN ] column_name TO new_column_name
ALTER FOREIGN TABLE [ IF EXISTS ] name
    RENAME TO new_name
ALTER FOREIGN TABLE [ IF EXISTS ] name
    SET SCHEMA new_schema


<phrase>where <replaceable class="parameter">action</replaceable> is one of:</phrase>

ここでactionは以下のいずれかです。

    ADD [ COLUMN ] column_name data_type [ COLLATE collation ] [ column_constraint [ ... ] ]
    DROP [ COLUMN ] [ IF EXISTS ] column_name [ RESTRICT | CASCADE ]
    ALTER [ COLUMN ] column_name [ SET DATA ] TYPE data_type [ COLLATE collation ]
    ALTER [ COLUMN ] column_name SET DEFAULT expression
    ALTER [ COLUMN ] column_name DROP DEFAULT
    ALTER [ COLUMN ] column_name { SET | DROP } NOT NULL
    ALTER [ COLUMN ] column_name SET STATISTICS integer
    ALTER [ COLUMN ] column_name SET ( attribute_option = value [, ... ] )
    ALTER [ COLUMN ] column_name RESET ( attribute_option [, ... ] )
    ALTER [ COLUMN ] column_name SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN | DEFAULT }
    ALTER [ COLUMN ] column_name OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ])
    ADD table_constraint [ NOT VALID ]
    VALIDATE CONSTRAINT constraint_name
    DROP CONSTRAINT [ IF EXISTS ]  constraint_name [ RESTRICT | CASCADE ]
    DISABLE TRIGGER [ trigger_name | ALL | USER ]
    ENABLE TRIGGER [ trigger_name | ALL | USER ]
    ENABLE REPLICA TRIGGER trigger_name
    ENABLE ALWAYS TRIGGER trigger_name
    SET WITHOUT OIDS
    INHERIT parent_table
    NO INHERIT parent_table
    OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
    OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ])

説明

<title>Description</title>

<command>ALTER FOREIGN TABLE</command> changes the definition of an existing foreign table. There are several subforms: ALTER FOREIGN TABLEは既存の外部テーブルの定義を変更します。 以下のように複数の副構文があります。

ADD COLUMN

This form adds a new column to the foreign table, using the same syntax as <link linkend="sql-createforeigntable"><command>CREATE FOREIGN TABLE</command></link>. Unlike the case when adding a column to a regular table, nothing happens to the underlying storage: this action simply declares that some new column is now accessible through the foreign table. この構文は、CREATE FOREIGN TABLEと同じ文法を使用して、外部テーブルに新しい列を追加します。 通常のテーブルに列を追加する場合と異なり、背後のストレージには何も起こりません。 この操作は単に、外部テーブルを通して何らかの新しい列がアクセスできるようになったことを宣言します。

DROP COLUMN [ IF EXISTS ]

This form drops a column from a foreign table. You will need to say <literal>CASCADE</literal> if anything outside the table depends on the column; for example, views. If <literal>IF EXISTS</literal> is specified and the column does not exist, no error is thrown. In this case a notice is issued instead. この構文は外部テーブルから列を削除します。 ビューなど何らかのその他のテーブルがこの列に依存する場合、CASCADEを付けなければなりません。 IF EXISTSが指定された場合、列が存在しなくてもエラーになりません。 この場合、注意メッセージが代わりに発生します。

SET DATA TYPE

This form changes the type of a column of a foreign table. Again, this has no effect on any underlying storage: this action simply changes the type that <productname>PostgreSQL</productname> believes the column to have. この構文は外部テーブルの列の型を変更します。 この場合も、背後のストレージには何の影響もありません。 この動作は単に、PostgreSQLが想定しているその列の型を変更するだけです。

SET/DROP DEFAULT

These forms set or remove the default value for a column. Default values only apply in subsequent <command>INSERT</command> or <command>UPDATE</command> commands; they do not cause rows already in the table to change. この構文は列に対するデフォルト値の設定または削除を行います。 デフォルト値はその後に行われるINSERTまたはUPDATEコマンドにのみ適用されます。 すでにテーブル内に存在する行の変更は行われません。

SET/DROP NOT NULL

Mark a column as allowing, or not allowing, null values. 列にNULL値を許すか許さないかどうか印を付けます。

SET STATISTICS

This form sets the per-column statistics-gathering target for subsequent <link linkend="sql-analyze"><command>ANALYZE</command></link> operations. See the similar form of <link linkend="sql-altertable"><command>ALTER TABLE</command></link> for more details. この構文は、この後のANALYZE操作における列単位の統計情報収集目標を設定します。 詳細についてはALTER TABLEの類似の構文を参照してください。

SET ( attribute_option = value [, ... ] )
RESET ( attribute_option [, ... ] )

This form sets or resets per-attribute options. See the similar form of <link linkend="sql-altertable"><command>ALTER TABLE</command></link> for more details. この構文は属性単位のオプションを設定またはリセットします。 詳細についてはALTER TABLEにおける類似の構文を参照してください。

SET STORAGE

This form sets the storage mode for a column. See the similar form of <link linkend="sql-altertable"><command>ALTER TABLE</command></link> for more details. Note that the storage mode has no effect unless the table's foreign-data wrapper chooses to pay attention to it. この構文は、列のストレージモードを設定します。 詳しくはALTER TABLEの類似の構文を参照して下さい。 ストレージモードは、テーブルの外部データラッパーがそれに注意するようになっていなければ、何の効果もないことに注意して下さい。

ADD table_constraint [ NOT VALID ]

This form adds a new constraint to a foreign table, using the same syntax as <link linkend="sql-createforeigntable"><command>CREATE FOREIGN TABLE</command></link>. Currently only <literal>CHECK</literal> constraints are supported. この構文は、CREATE FOREIGN TABLEと同じ構文を使って、外部テーブルに新しい制約を追加します。 現在のところ、CHECK制約のみがサポートされています。

Unlike the case when adding a constraint to a regular table, nothing is done to verify the constraint is correct; rather, this action simply declares that some new condition should be assumed to hold for all rows in the foreign table. (See the discussion in <link linkend="sql-createforeigntable"><command>CREATE FOREIGN TABLE</command></link>.) If the constraint is marked <literal>NOT VALID</literal>, then it isn't assumed to hold, but is only recorded for possible future use. 通常のテーブルに制約を追加する場合とは異なり、制約が正しいことを検証するために、何も実行されません。 そうではなく、この動作は単に、ある新しい条件が、外部テーブルのすべての行に対して成り立つことを仮定すべきだと宣言するものです。 (CREATE FOREIGN TABLEの記述を参照して下さい。) 制約がNOT VALIDであるとされている場合、それが成り立つことは仮定されず、将来利用される場合に備えて記録されているだけになります。

VALIDATE CONSTRAINT

This form marks as valid a constraint that was previously marked as <literal>NOT VALID</literal>. No action is taken to verify the constraint, but future queries will assume that it holds. この構文は、それまでNOT VALIDであるとされていた制約をvalidに変更します。 制約を検証するために何の動作も実行されませんが、以後の問い合わせではそれが成り立つと仮定されます。

DROP CONSTRAINT [ IF EXISTS ]

This form drops the specified constraint on a foreign table. If <literal>IF EXISTS</literal> is specified and the constraint does not exist, no error is thrown. In this case a notice is issued instead. この構文は、外部テーブル上の指定された制約を削除します。 IF EXISTSが指定され、その制約が存在しない場合は、エラーにはなりません。 その場合、代わりに注意が発行されます。

DISABLE/ENABLE [ REPLICA | ALWAYS ] TRIGGER

These forms configure the firing of trigger(s) belonging to the foreign table. See the similar form of <link linkend="sql-altertable"><command>ALTER TABLE</command></link> for more details. これらの構文は外部テーブルに属するトリガの発行について設定します。 詳細についてはALTER TABLEにおける類似の構文を参照してください。

SET WITHOUT OIDS

Backward compatibility syntax for removing the <literal>oid</literal> system column. As <literal>oid</literal> system columns cannot be added anymore, this never has an effect. システム列oidを削除する、後方互換のための構文です。 システム列oidは今では追加できませんので、これは効果がありません。

INHERIT parent_table

This form adds the target foreign table as a new child of the specified parent table. See the similar form of <link linkend="sql-altertable"><command>ALTER TABLE</command></link> for more details. この構文は対象の外部テーブルを指定した親テーブルの新しい子テーブルとして追加します。 詳しくはALTER TABLEの類似の構文を参照して下さい。

NO INHERIT parent_table

This form removes the target foreign table from the list of children of the specified parent table. この構文は、対象の外部テーブルを指定した親テーブルの子テーブルのリストから削除します。

OWNER

This form changes the owner of the foreign table to the specified user. この構文は外部テーブルの所有者を指定ユーザに変更します。

OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ] )

Change options for the foreign table or one of its columns. <literal>ADD</literal>, <literal>SET</literal>, and <literal>DROP</literal> specify the action to be performed. <literal>ADD</literal> is assumed if no operation is explicitly specified. Duplicate option names are not allowed (although it's OK for a table option and a column option to have the same name). Option names and values are also validated using the foreign data wrapper library. 外部テーブルもしくはその列の1つについてのオプションを変更します。 ADDSETDROPは実行する操作を指定します。 明示的な操作指定がない場合ADDとみなされます。 重複したオプション名は許されません。 (しかしテーブルオプションと列オプションとで同じ名前を持たせることは問題ありません。) またオプションの名前と値は外部データラッパーのライブラリを使用して検証されます。

RENAME

The <literal>RENAME</literal> forms change the name of a foreign table or the name of an individual column in a foreign table. RENAME構文は外部テーブルの名前または外部テーブル内の個々の列の名前を変更します。

SET SCHEMA

This form moves the foreign table into another schema. この構文は外部テーブルを別のスキーマに移動します。

All the actions except <literal>RENAME</literal> and <literal>SET SCHEMA</literal> can be combined into a list of multiple alterations to apply in parallel. For example, it is possible to add several columns and/or alter the type of several columns in a single command. RENAMEおよびSET SCHEMA以外の操作はすべて、複数変更項目リストにまとめて並行に適用することができます。 例えば、複数の列の追加、複数の列の型変更、またはその両方を単一のコマンドで行うことができます。

If the command is written as <literal>ALTER FOREIGN TABLE IF EXISTS ...</literal> and the foreign table does not exist, no error is thrown. A notice is issued in this case. コマンドがALTER FOREIGN TABLE IF EXISTS ...と記述されていて外部テーブルが存在しない場合、エラーにはなりません。 この場合、注意が発行されます。

You must own the table to use <command>ALTER FOREIGN TABLE</command>. To change the schema of a foreign table, you must also have <literal>CREATE</literal> privilege on the new schema. To alter the owner, you must be able to <literal>SET ROLE</literal> to the new owning role, and that role must have <literal>CREATE</literal> privilege on the table's schema. (These restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the table. However, a superuser can alter ownership of any table anyway.) To add a column or alter a column type, you must also have <literal>USAGE</literal> privilege on the data type. ALTER FOREIGN TABLEを使用するためにはテーブルの所有者でなければなりません。 また外部テーブルのスキーマを変更するためには、新しいスキーマに対してCREATE権限を持っていなければなりません。 所有者を変更するには、新しい所有者ロールに対してSET ROLEができなければなりません。また、そのロールはテーブルのスキーマにおいてCREATE権限を持たなければなりません。 (これらの制限により、テーブルの削除と再作成を行ってもできないことを所有者の変更で行えないようにします。 しかし、スーパーユーザはどのテーブルの所有者も変更できます。) 列の追加または列の型の変更を行うためには、そのデータ型に対するUSAGE権限も必要です。

パラメータ

<title>Parameters</title>
name

The name (possibly schema-qualified) of an existing foreign table to alter. If <literal>ONLY</literal> is specified before the table name, only that table is altered. If <literal>ONLY</literal> is not specified, the table and all its descendant tables (if any) are altered. Optionally, <literal>*</literal> can be specified after the table name to explicitly indicate that descendant tables are included. 変更対象の既存外部テーブルの名前(スキーマ修飾可)です。 テーブル名の前にONLYが指定されていた場合、そのテーブルのみが変更されます。 ONLYが指定されていない場合、そのテーブルと、そのすべての子孫のテーブル(あれば)が変更されます。 子孫のテーブルが含まれることを明示的に示すために、テーブル名の後に*を指定することができますが、これは省略可能です。

column_name

Name of a new or existing column. 新しい列または既存の列の名前です。

new_column_name

New name for an existing column. 既存の列に対する新しい名前です。

new_name

New name for the table. テーブルの新しい名前です。

data_type

Data type of the new column, or new data type for an existing column. 新しい列のデータ型、または既存の列に対する新しいデータ型です。

table_constraint

New table constraint for the foreign table. 外部テーブルの新しいテーブル制約です。

constraint_name

Name of an existing constraint to drop. 削除する既存の制約の名前です。

CASCADE

Automatically drop objects that depend on the dropped column or constraint (for example, views referencing the column), and in turn all objects that depend on those objects (see <xref linkend="ddl-depend"/>). 削除される列または制約に依存するオブジェクト(その列を参照するビューなど)を自動的に削除し、さらにそれらのオブジェクトに依存するすべてのオブジェクトも削除します(5.14参照)。

RESTRICT

Refuse to drop the column or constraint if there are any dependent objects. This is the default behavior. 依存するオブジェクトが存在する場合、列または制約の削除を拒否します。 これがデフォルトの動作です。

trigger_name

Name of a single trigger to disable or enable. 無効にする、あるいは有効にするトリガの名前です。

ALL

Disable or enable all triggers belonging to the foreign table. (This requires superuser privilege if any of the triggers are internally generated triggers. The core system does not add such triggers to foreign tables, but add-on code could do so.) 外部テーブルに属するすべてのトリガを無効、あるいは有効にします。 (内部的に生成されたトリガが含まれる場合、スーパーユーザ権限が必要です。 コアシステムは外部テーブルにそのようなトリガを追加することはありませんが、アドオンが追加することはあり得ます。)

USER

Disable or enable all triggers belonging to the foreign table except for internally generated triggers. 内部的に生成されたトリガを除き、外部テーブルに属するすべてのトリガを無効、あるいは有効にします。

parent_table

A parent table to associate or de-associate with this foreign table. 外部テーブルと関連付ける、あるいは関連を取り消す親テーブルです。

new_owner

The user name of the new owner of the table. テーブルの新しい所有者のユーザ名です。

new_schema

The name of the schema to which the table will be moved. テーブルの移動先となるスキーマの名前です。

注釈

<title>Notes</title>

The key word <literal>COLUMN</literal> is noise and can be omitted. COLUMNキーワードには意味がなく、省略可能です。

Consistency with the foreign server is not checked when a column is added or removed with <literal>ADD COLUMN</literal> or <literal>DROP COLUMN</literal>, a <literal>NOT NULL</literal> or <literal>CHECK</literal> constraint is added, or a column type is changed with <literal>SET DATA TYPE</literal>. It is the user's responsibility to ensure that the table definition matches the remote side. ADD COLUMNまたはDROP COLUMNにより列が追加、削除される時、NOT NULLまたはCHECK制約が追加される時、SET DATA TYPEにより列の型が変更される時、外部サーバとの一貫性は検査されません。 確実にテーブル定義をリモート側に合わせることはユーザの責任です。

Refer to <link linkend="sql-createforeigntable"><command>CREATE FOREIGN TABLE</command></link> for a further description of valid parameters. 有効なパラメータに関する詳しい説明についてはCREATE FOREIGN TABLEを参照してください。

<title>Examples</title>

To mark a column as not-null: 列を非NULLと印付けします。

ALTER FOREIGN TABLE distributors ALTER COLUMN street SET NOT NULL;

To change options of a foreign table: 外部テーブルのオプションを変更します。

ALTER FOREIGN TABLE myschema.distributors OPTIONS (ADD opt1 'value', SET opt2 'value2', DROP opt3);

互換性

<title>Compatibility</title>

The forms <literal>ADD</literal>, <literal>DROP</literal>, and <literal>SET DATA TYPE</literal> conform with the SQL standard. The other forms are <productname>PostgreSQL</productname> extensions of the SQL standard. Also, the ability to specify more than one manipulation in a single <command>ALTER FOREIGN TABLE</command> command is an extension. ADDDROPSET DATA TYPE構文は標準SQLに準拠します。 他の構文は標準SQLに対するPostgreSQLの拡張です。 単一のALTER FOREIGN TABLEコマンドに複数の操作を指定する機能も拡張です。

<command>ALTER FOREIGN TABLE DROP COLUMN</command> can be used to drop the only column of a foreign table, leaving a zero-column table. This is an extension of SQL, which disallows zero-column foreign tables. ALTER FOREIGN TABLE DROP COLUMNを用いて外部テーブルのたった1つの列を削除してゼロ列のテーブルとすることができます。 これは拡張であり、SQLではゼロ列の外部テーブルを許しません。

関連項目

<title>See Also</title> CREATE FOREIGN TABLE, DROP FOREIGN TABLE