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

CREATE MATERIALIZED VIEW

CREATE MATERIALIZED VIEW <refpurpose>define a new materialized view</refpurpose> — 新しいマテリアライズドビューを定義する

概要

CREATE MATERIALIZED VIEW [ IF NOT EXISTS ] table_name
    [ (column_name [, ...] ) ]
    [ USING method ]
    [ WITH ( storage_parameter [= value] [, ... ] ) ]
    [ TABLESPACE tablespace_name ]
    AS query
    [ WITH [ NO ] DATA ]

説明

<title>Description</title>

<command>CREATE MATERIALIZED VIEW</command> defines a materialized view of a query. The query is executed and used to populate the view at the time the command is issued (unless <command>WITH NO DATA</command> is used) and may be refreshed later using <command>REFRESH MATERIALIZED VIEW</command>. CREATE MATERIALIZED VIEWは問い合わせからマテリアライズドビューを定義します。 この問い合わせはコマンド発行時にビューにデータを投入する(WITH NO DATAが使用されていない場合)ために実行され、使用されます。 また将来のREFRESH MATERIALIZED VIEWの使用で更新されるかもしれません。

<command>CREATE MATERIALIZED VIEW</command> is similar to <command>CREATE TABLE AS</command>, except that it also remembers the query used to initialize the view, so that it can be refreshed later upon demand. A materialized view has many of the same properties as a table, but there is no support for temporary materialized views. CREATE MATERIALIZED VIEWCREATE TABLE ASと似ていますが、必要に応じて後で更新できるように、ビューの初期化時に使用された問い合わせを記憶する点が異なります。 マテリアライズドビューはテーブルと同じ属性を多く持ちますが、一時的なマテリアライズドビューをサポートしていません。

<command>CREATE MATERIALIZED VIEW</command> requires <literal>CREATE</literal> privilege on the schema used for the materialized view. CREATE MATERIALIZED VIEWには、マテリアライズドビューのために使われるスキーマでのCREATE権限が必要です。

パラメータ

<title>Parameters</title>
IF NOT EXISTS

Do not throw an error if a materialized view with the same name already exists. A notice is issued in this case. Note that there is no guarantee that the existing materialized view is anything like the one that would have been created. 同じ名前のマテリアライズドビューが既に存在する場合にエラーとしません。 この場合、注意が発行されます。 既存のマテリアライズドビューが作成されようとしていたものと類似のものであることは全く保証されないことに注意してください。

table_name

The name (optionally schema-qualified) of the materialized view to be created. The name must be distinct from the name of any other relation (table, sequence, index, view, materialized view, or foreign table) in the same schema. 作成するマテリアライズドビューの名前です(スキーマ修飾も可)。 この名前は、同じスキーマ内にある他のリレーション(テーブル、シーケンス、インデックス、ビュー、マテリアライズドビュー、外部テーブル)と異なるものでなければなりません。

column_name

The name of a column in the new materialized view. If column names are not provided, they are taken from the output column names of the query. 新しいマテリアライズドビューの列の名前です。 列名が提供されていない場合の列名は、問い合わせの出力列名から取られます。

USING method

This optional clause specifies the table access method to use to store the contents for the new materialized view; the method needs be an access method of type <literal>TABLE</literal>. See <xref linkend="tableam"/> for more information. If this option is not specified, the default table access method is chosen for the new materialized view. See <xref linkend="guc-default-table-access-method"/> for more information. この省略可能な句は、新しいマテリアライズドビューの内容を保存するのに使うテーブルアクセスメソッドを指定します。メソッドはTABLE型のアクセスメソッドであることが必要です。 より詳しい情報は第63章を参照してください。 このオプションが指定されなければ、新しいマテリアライズドビューに対してはデフォルトのテーブルアクセスメソッドが選ばれます。 より詳しい情報はdefault_table_access_methodを参照してください。

WITH ( storage_parameter [= value] [, ... ] )

This clause specifies optional storage parameters for the new materialized view; see <xref linkend="sql-createtable-storage-parameters"/> in the <xref linkend="sql-createtable"/> documentation for more information. All parameters supported for <literal>CREATE TABLE</literal> are also supported for <literal>CREATE MATERIALIZED VIEW</literal>. See <xref linkend="sql-createtable"/> for more information. この句は、新しいマテリアライズドビューの格納パラメータ(省略可能)を指定します。 詳細についてはCREATE TABLEの文書の格納パラメータを参照してください。 CREATE TABLEでサポートされるすべてのパラメータはCREATE MATERIALIZED VIEWでもサポートされます。 詳細についてはCREATE TABLEを参照してください。

TABLESPACE tablespace_name

The <replaceable class="parameter">tablespace_name</replaceable> is the name of the tablespace in which the new materialized view is to be created. If not specified, <xref linkend="guc-default-tablespace"/> is consulted. tablespace_nameはマテリアライズドビューが作成されるテーブル空間の名前です。 指定されていない場合はdefault_tablespaceを参照します。

query

A <link linkend="sql-select"><command>SELECT</command></link>, <link linkend="sql-table"><command>TABLE</command></link>, or <link linkend="sql-values"><command>VALUES</command></link> command. This query will run within a security-restricted operation; in particular, calls to functions that themselves create temporary tables will fail. SELECTTABLEまたはVALUESコマンドです。 この問い合わせはセキュリティ限定された操作の中で実行されます。 具体的には一時テーブルを作成する関数の呼び出しは失敗します。

WITH [ NO ] DATA

This clause specifies whether or not the materialized view should be populated at creation time. If not, the materialized view will be flagged as unscannable and cannot be queried until <command>REFRESH MATERIALIZED VIEW</command> is used. この句は作成時にマテリアライズドビューにデータを投入するかどうかを指定します。 投入しない場合、マテリアライズドビューはスキャン不可という印が付き、REFRESH MATERIALIZED VIEWが使用されるまで問い合わせることができません。

互換性

<title>Compatibility</title>

<command>CREATE MATERIALIZED VIEW</command> is a <productname>PostgreSQL</productname> extension. CREATE MATERIALIZED VIEWPostgreSQLの拡張です。

関連項目

<title>See Also</title> ALTER MATERIALIZED VIEW, CREATE TABLE AS, CREATE VIEW, DROP MATERIALIZED VIEW, REFRESH MATERIALIZED VIEW