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

CREATE TABLE

CREATE TABLE <refpurpose>define a new table</refpurpose> — 新しいテーブルを定義する

概要

CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXISTS ] table_name ( [
  { column_name data_type [ STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN | DEFAULT } ] [ COMPRESSION compression_method ] [ COLLATE collation ] [ column_constraint [ ... ] ]
    | table_constraint
    | LIKE source_table [ like_option ... ] }
    [, ... ]
] )
[ INHERITS ( parent_table [, ... ] ) ]
[ PARTITION BY { RANGE | LIST | HASH } ( { column_name | ( expression ) } [ COLLATE collation ] [ opclass ] [, ... ] ) ]
[ USING method ]
[ WITH ( storage_parameter [= value] [, ... ] ) | WITHOUT OIDS ]
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
[ TABLESPACE tablespace_name ]

CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXISTS ] table_name
    OF type_name [ (
  { column_name [ WITH OPTIONS ] [ column_constraint [ ... ] ]
    | table_constraint }
    [, ... ]
) ]
[ PARTITION BY { RANGE | LIST | HASH } ( { column_name | ( expression ) } [ COLLATE collation ] [ opclass ] [, ... ] ) ]
[ USING method ]
[ WITH ( storage_parameter [= value] [, ... ] ) | WITHOUT OIDS ]
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
[ TABLESPACE tablespace_name ]

CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXISTS ] table_name
    PARTITION OF parent_table [ (
  { column_name [ WITH OPTIONS ] [ column_constraint [ ... ] ]
    | table_constraint }
    [, ... ]
) ] { FOR VALUES partition_bound_spec | DEFAULT }
[ PARTITION BY { RANGE | LIST | HASH } ( { column_name | ( expression ) } [ COLLATE collation ] [ opclass ] [, ... ] ) ]
[ USING method ]
[ WITH ( storage_parameter [= value] [, ... ] ) | WITHOUT OIDS ]
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
[ TABLESPACE tablespace_name ]


<phrase>where <replaceable class="parameter">column_constraint</replaceable> is:</phrase>

ここでcolumn_constraintには、次の構文が入ります。

[ CONSTRAINT constraint_name ]
{ NOT NULL |
  NULL |
  CHECK ( expression ) [ NO INHERIT ] |
  DEFAULT default_expr |
  GENERATED ALWAYS AS ( generation_expr ) STORED |
  GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ( sequence_options ) ] |
  UNIQUE [ NULLS [ NOT ] DISTINCT ] index_parameters |
  PRIMARY KEY index_parameters |
  REFERENCES reftable [ ( refcolumn ) ] [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ]
    [ ON DELETE referential_action ] [ ON UPDATE referential_action ] }
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]


<phrase>and <replaceable class="parameter">table_constraint</replaceable> is:</phrase>

また、table_constraintには、次の構文が入ります。

[ CONSTRAINT constraint_name ]
{ CHECK ( expression ) [ NO INHERIT ] |
  UNIQUE [ NULLS [ NOT ] DISTINCT ] ( column_name [, ... ] ) index_parameters |
  PRIMARY KEY ( column_name [, ... ] ) index_parameters |
  EXCLUDE [ USING index_method ] ( exclude_element WITH operator [, ... ] ) index_parameters [ WHERE ( predicate ) ] |
  FOREIGN KEY ( column_name [, ... ] ) REFERENCES reftable [ ( refcolumn [, ... ] ) ]
    [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ] [ ON DELETE referential_action ] [ ON UPDATE referential_action ] }
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]


<phrase>and <replaceable class="parameter">like_option</replaceable> is:</phrase>

またlike_optionは、以下の通りです。

{ INCLUDING | EXCLUDING } { COMMENTS | COMPRESSION | CONSTRAINTS | DEFAULTS | GENERATED | IDENTITY | INDEXES | STATISTICS | STORAGE | ALL }


<phrase>and <replaceable class="parameter">partition_bound_spec</replaceable> is:</phrase>

またpartition_bound_specは、以下の通りです。

IN ( partition_bound_expr [, ...] ) |
FROM ( { partition_bound_expr | MINVALUE | MAXVALUE } [, ...] )
  TO ( { partition_bound_expr | MINVALUE | MAXVALUE } [, ...] ) |
WITH ( MODULUS numeric_literal, REMAINDER numeric_literal )


<phrase><replaceable class="parameter">index_parameters</replaceable> in <literal>UNIQUE</literal>, <literal>PRIMARY KEY</literal>, and <literal>EXCLUDE</literal> constraints are:</phrase>

UNIQUEPRIMARY KEYおよびEXCLUDE制約内のindex_parametersは以下の通りです。

[ INCLUDE ( column_name [, ... ] ) ]
[ WITH ( storage_parameter [= value] [, ... ] ) ]
[ USING INDEX TABLESPACE tablespace_name ]


<phrase><replaceable class="parameter">exclude_element</replaceable> in an <literal>EXCLUDE</literal> constraint is:</phrase>

EXCLUDE制約内のexclude_elementは以下の通りです。

{ column_name | ( expression ) } [ opclass ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ]


<phrase><replaceable class="parameter">referential_action</replaceable> in a <literal>FOREIGN KEY</literal>/<literal>REFERENCES</literal> constraint is:</phrase>

FOREIGN KEY/REFERENCES制約内のreferential_actionは以下の通りです。

{ NO ACTION | RESTRICT | CASCADE | SET NULL [ ( column_name [, ... ] ) ] | SET DEFAULT [ ( column_name [, ... ] ) ] }

説明

<title>Description</title>

<command>CREATE TABLE</command> will create a new, initially empty table in the current database. The table will be owned by the user issuing the command. CREATE TABLEは、現在のデータベースに新しい空のテーブルを作成します。 作成したテーブルはこのコマンドを実行したユーザが所有します。

If a schema name is given (for example, <literal>CREATE TABLE myschema.mytable ...</literal>) then the table is created in the specified schema. Otherwise it is created in the current schema. Temporary tables exist in a special schema, so a schema name cannot be given when creating a temporary table. The name of the table must be distinct from the name of any other relation (table, sequence, index, view, materialized view, or foreign table) in the same schema. スキーマ名が付けられている場合(例えば、CREATE TABLE myschema.mytable ...)、テーブルは指定されたスキーマに作成されます。 スキーマ名がなければ、テーブルは現在のスキーマに作成されます。 また、一時テーブルは特別なスキーマに存在するため、一時テーブルの作成時にスキーマ名を与えることはできません。 テーブル名は、同じスキーマ内の他のリレーション(テーブル、シーケンス、インデックス、ビュー、マテリアライズドビュー、外部テーブル)とは異なる名前にする必要があります。

<command>CREATE TABLE</command> also automatically creates a data type that represents the composite type corresponding to one row of the table. Therefore, tables cannot have the same name as any existing data type in the same schema. さらに、CREATE TABLEは、作成するテーブルの1行に対応する複合型のデータ型を作成します。 したがって、テーブルは、同じスキーマ内の既存のデータ型と同じ名前を持つことができません。

The optional constraint clauses specify constraints (tests) that new or updated rows must satisfy for an insert or update operation to succeed. A constraint is an SQL object that helps define the set of valid values in the table in various ways. 制約句には、挿入、更新操作を行うときに、新しい行、または更新する行が満たさなければならない制約(検査項目)を指定します。制約句は省略可能です。 制約は、テーブル内で有効な値の集合を様々な方法で定義できるSQLオブジェクトです。

There are two ways to define constraints: table constraints and column constraints. A column constraint is defined as part of a column definition. A table constraint definition is not tied to a particular column, and it can encompass more than one column. Every column constraint can also be written as a table constraint; a column constraint is only a notational convenience for use when the constraint only affects one column. 制約の定義にはテーブル制約と列制約という2種類があります。 列制約は列定義の一部として定義されます。 テーブル制約定義は、特定の列とは結びつけられておらず、複数の列を含有することができます。 また、全ての列制約はテーブル制約として記述することができます。 列制約は、1つの列にのみ影響する制約のための、簡便な記述方法に過ぎません。

To be able to create a table, you must have <literal>USAGE</literal> privilege on all column types or the type in the <literal>OF</literal> clause, respectively. テーブルを作成するためには、すべての列の型またはOF句中の型に対するUSAGE権限を持たなければなりません。

パラメータ

<title>Parameters</title>
TEMPORARYまたはTEMP #

If specified, the table is created as a temporary table. Temporary tables are automatically dropped at the end of a session, or optionally at the end of the current transaction (see <literal>ON COMMIT</literal> below). The default search_path includes the temporary schema first and so identically named existing permanent tables are not chosen for new plans while the temporary table exists, unless they are referenced with schema-qualified names. Any indexes created on a temporary table are automatically temporary as well. このパラメータが指定された場合、テーブルは一時テーブルとして作成されます。 一時テーブルは、そのセッションの終わり、場合によっては、現在のトランザクションの終わり(後述のON COMMITを参照)に自動的に削除されます。 デフォルトのsearch_pathは一時スキーマを最初に含んでいますので、同じ名前を持つ既存の永続テーブルは、スキーマ修飾名で参照されていない限り、一時テーブルが存在する間は非可視になります。 一時テーブルに作られるインデックスも、全て自動的に一時的なものとなります。

The <link linkend="autovacuum">autovacuum daemon</link> cannot access and therefore cannot vacuum or analyze temporary tables. For this reason, appropriate vacuum and analyze operations should be performed via session SQL commands. For example, if a temporary table is going to be used in complex queries, it is wise to run <command>ANALYZE</command> on the temporary table after it is populated. 自動バキュームデーモンは一時テーブルにアクセスできないため、一時テーブルのバキュームや解析を行うことはできません。 このためセッションのSQLコマンドを用いて適切なバキュームと解析を実行しなければなりません。 例えば、一時テーブルが複雑な問い合わせで使用される場合、一時テーブルにデータを投入した後にそれに対しANALYZEを実行することを勧めます。

Optionally, <literal>GLOBAL</literal> or <literal>LOCAL</literal> can be written before <literal>TEMPORARY</literal> or <literal>TEMP</literal>. This presently makes no difference in <productname>PostgreSQL</productname> and is deprecated; see <xref linkend="sql-createtable-compatibility"/> below. オプションで、GLOBALまたはLOCALTEMPORARYTEMPの前に記述することができます。 PostgreSQLでは、現在違いがなく、廃止予定です。 互換性を参照してください。

UNLOGGED #

If specified, the table is created as an unlogged table. Data written to unlogged tables is not written to the write-ahead log (see <xref linkend="wal"/>), which makes them considerably faster than ordinary tables. However, they are not crash-safe: an unlogged table is automatically truncated after a crash or unclean shutdown. The contents of an unlogged table are also not replicated to standby servers. Any indexes created on an unlogged table are automatically unlogged as well. 指定された場合、テーブルはログを取らないテーブルとして作成されます。 ログを取らないテーブルに書き出されたデータは先行書き込みログ(第30章参照)には書き出されません。 このため通常のテーブルより相当高速になります。 しかしこれらはクラッシュ時に安全ではありません。 クラッシュまたは異常停止の後、ログを取らないテーブルは自動的に切り詰められます。 またログを取らないテーブルの内容はスタンバイサーバにコピーされません。 ログを取らないテーブル上に作成されたインデックスはすべて同様に、ログを取らないようになります。

If this is specified, any sequences created together with the unlogged table (for identity or serial columns) are also created as unlogged. これを指定すると、(ID列またはシリアル列用の)ログを取らないテーブルと一緒に作成されたシーケンスも、ログを取らないものとして作成されます。

IF NOT EXISTS #

Do not throw an error if a relation with the same name already exists. A notice is issued in this case. Note that there is no guarantee that the existing relation is anything like the one that would have been created. 同じ名前のリレーションがすでに存在していてもエラーとしません。 この場合注意が発せられます。 既存のリレーションが作成しようとしたものと何かしら似たものであることは保証されません。

table_name #

The name (optionally schema-qualified) of the table to be created. 作成するテーブルの名前です(スキーマ修飾名でも可)。

OF type_name #

Creates a <firstterm>typed table</firstterm>, which takes its structure from the specified composite type (name optionally schema-qualified). A typed table is tied to its type; for example the table will be dropped if the type is dropped (with <literal>DROP TYPE ... CASCADE</literal>). 指定した複合型(スキーマ修飾可能)から構造を取り出した型付きテーブルを作成します。 型付きテーブルはその型に束縛されます。 例えば、型が(DROP TYPE ... CASCADEで)削除されるとそのテーブルは削除されます。

When a typed table is created, then the data types of the columns are determined by the underlying composite type and are not specified by the <literal>CREATE TABLE</literal> command. But the <literal>CREATE TABLE</literal> command can add defaults and constraints to the table and can specify storage parameters. 型付きテーブルが作成されると、その列のデータ型は背後の複合型により決定され、CREATE TABLEコマンドでは指定されません。 しかしCREATE TABLEコマンドではテーブルにデフォルトと制約を追加できます。 また、格納パラメータの指定も可能です。

column_name #

The name of a column to be created in the new table. 新しいテーブルで作成される列の名前です。

data_type #

The data type of the column. This can include array specifiers. For more information on the data types supported by <productname>PostgreSQL</productname>, refer to <xref linkend="datatype"/>. 列のデータ型です。 これには、配列指定子を含めることができます。 PostgreSQLでサポートされるデータ型の情報に関する詳細は第8章を参照してください。

COLLATE collation #

The <literal>COLLATE</literal> clause assigns a collation to the column (which must be of a collatable data type). If not specified, the column data type's default collation is used. COLLATE句は列(照合順の設定が可能なデータ型でなければなりません)に照合順を割り当てます。 指定がなければ、列のデータ型のデフォルトの照合順が使用されます。

STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN | DEFAULT } #

This form sets the storage mode for the column. This controls whether this column is held inline or in a secondary <acronym>TOAST</acronym> table, and whether the data should be compressed or not. <literal>PLAIN</literal> must be used for fixed-length values such as <type>integer</type> and is inline, uncompressed. <literal>MAIN</literal> is for inline, compressible data. <literal>EXTERNAL</literal> is for external, uncompressed data, and <literal>EXTENDED</literal> is for external, compressed data. Writing <literal>DEFAULT</literal> sets the storage mode to the default mode for the column's data type. <literal>EXTENDED</literal> is the default for most data types that support non-<literal>PLAIN</literal> storage. Use of <literal>EXTERNAL</literal> will make substring operations on very large <type>text</type> and <type>bytea</type> values run faster, at the penalty of increased storage space. See <xref linkend="storage-toast"/> for more information. この構文は、列の格納モードを設定します。 これは、この列をインラインに保持するか、二次的なTOASTテーブルに保持するか、およびデータを圧縮する必要があるかどうかを制御します。 PLAINは、integerなどの固定長の値に使用することが必要で、インラインで、非圧縮です。 MAINはインラインで、圧縮可能なデータに対するものです。 EXTERNALは外部で、非圧縮データであり、EXTENDEDは外部で、圧縮されたデータに使用されます。 DEFAULTと書くと、列のデータ型に対して格納モードをデフォルトのモードに設定します。 EXTENDEDは、PLAIN以外の保管をサポートするほとんどのデータ型におけるデフォルトです。 EXTERNALを使用すると、非常に長いtextおよびbytea列に対する部分文字列操作の処理速度が向上しますが、必要な保管容量が増えるというデメリットがあります。 詳細は、73.2を参照してください。

COMPRESSION compression_method #

The <literal>COMPRESSION</literal> clause sets the compression method for the column. Compression is supported only for variable-width data types, and is used only when the column's storage mode is <literal>main</literal> or <literal>extended</literal>. (See <xref linkend="sql-altertable"/> for information on column storage modes.) Setting this property for a partitioned table has no direct effect, because such tables have no storage of their own, but the configured value will be inherited by newly-created partitions. The supported compression methods are <literal>pglz</literal> and <literal>lz4</literal>. (<literal>lz4</literal> is available only if <option>&#45;-with-lz4</option> was used when building <productname>PostgreSQL</productname>.) In addition, <replaceable class="parameter">compression_method</replaceable> can be <literal>default</literal> to explicitly specify the default behavior, which is to consult the <xref linkend="guc-default-toast-compression"/> setting at the time of data insertion to determine the method to use. COMPRESSION句は列の圧縮法を設定します。圧縮は可変幅データ型に対してのみサポートされていて、列の格納モードがmainまたはextendedの場合にのみ使われます。 (列の格納モードについての情報はALTER TABLEを参照してください。) パーティションテーブルには自身のストレージがありませんので、パーティションテーブルに対してこの属性を設定しても直接の影響はありませんが、設定値は新しく作成されるパーティションに継承されます。 サポートされている圧縮法はpglzlz4です。 (lz4は、PostgreSQL構築時に--with-lz4が使われた場合にのみ利用可能です。) さらにcompression_methodは、明示的にデフォルトの動作を指定するためにdefaultとすることもできます。その場合、利用する圧縮法を決定するためにデータ挿入時にdefault_toast_compression設定を調べます。

INHERITS ( parent_table [, ... ] ) #

The optional <literal>INHERITS</literal> clause specifies a list of tables from which the new table automatically inherits all columns. Parent tables can be plain tables or foreign tables. オプションのINHERITS句でテーブルの一覧を指定すると、新しいテーブルは指定されたテーブルの全ての列を自動的に継承します。 親テーブルには通常のテーブルまたは外部テーブルを指定できます。

Use of <literal>INHERITS</literal> creates a persistent relationship between the new child table and its parent table(s). Schema modifications to the parent(s) normally propagate to children as well, and by default the data of the child table is included in scans of the parent(s). INHERITSを使用すると、新しい子テーブルとその親テーブル(複数可)との間に永続的な関連が作成されます。 通常、親へのスキーマ変更は子にも伝播します。また、デフォルトでは、親テーブルの走査結果には子テーブルのデータが含まれます。

If the same column name exists in more than one parent table, an error is reported unless the data types of the columns match in each of the parent tables. If there is no conflict, then the duplicate columns are merged to form a single column in the new table. If the column name list of the new table contains a column name that is also inherited, the data type must likewise match the inherited column(s), and the column definitions are merged into one. If the new table explicitly specifies a default value for the column, this default overrides any defaults from inherited declarations of the column. Otherwise, any parents that specify default values for the column must all specify the same default, or an error will be reported. 複数の親テーブルに同一名の列が存在する場合、それらのデータ型が一致していなければ、エラーとして報告されます。 競合がなければ、これらの重複した列は新しいテーブルで1つの列の形に融合されます。 新しいテーブルの列名の一覧に継承する列の名前が含まれる場合も、そのデータ型は継承する列のデータ型と一致していなければなりません。さらに、その列定義は1つに融合されます。 新しいテーブルで明示的に列のデフォルト値を指定した場合、継承した列宣言における全てのデフォルト値は上書きされます。 デフォルト値を指定しなかった場合、親側でデフォルト値が指定されている時は、それらのデフォルト値が全て同じ値でなければなりません。 値が違う場合はエラーになります。

<literal>CHECK</literal> constraints are merged in essentially the same way as columns: if multiple parent tables and/or the new table definition contain identically-named <literal>CHECK</literal> constraints, these constraints must all have the same check expression, or an error will be reported. Constraints having the same name and expression will be merged into one copy. A constraint marked <literal>NO INHERIT</literal> in a parent will not be considered. Notice that an unnamed <literal>CHECK</literal> constraint in the new table will never be merged, since a unique name will always be chosen for it. CHECK制約は、基本的には列と同様の方法でマージされます。 複数の親テーブル、新しいテーブル、またはその両方の定義に同じ名前のCHECK制約が存在した場合、これらの制約はすべて同じ検査式を持たなければなりません。 さもなくば、エラーが報告されます。 同じ名前と式を持つ制約は1つのコピーにまとめられます。 親テーブルでNO INHERITと印が付いた制約は考慮されません。 新しいテーブル内の無名のCHECK制約は、一意な名前が必ず作られるため、マージされないことに注意してください。

Column <literal>STORAGE</literal> settings are also copied from parent tables. 列のSTORAGE設定もまた親テーブルからコピーされます。

If a column in the parent table is an identity column, that property is not inherited. A column in the child table can be declared identity column if desired. 親テーブルのある列がIDENTITY列の場合、その属性は継承されません。 望むなら子テーブルの列をIDENTITY列と宣言することができます。

PARTITION BY { RANGE | LIST | HASH } ( { column_name | ( expression ) } [ opclass ] [, ...] ) #

The optional <literal>PARTITION BY</literal> clause specifies a strategy of partitioning the table. The table thus created is called a <firstterm>partitioned</firstterm> table. The parenthesized list of columns or expressions forms the <firstterm>partition key</firstterm> for the table. When using range or hash partitioning, the partition key can include multiple columns or expressions (up to 32, but this limit can be altered when building <productname>PostgreSQL</productname>), but for list partitioning, the partition key must consist of a single column or expression. オプションのPARTITION BY句により、テーブルのパーティショニングの戦略を指定できます。 このようにして作られたテーブルをパーティションテーブルと呼びます。 括弧に囲まれた列や式のリストはテーブルのパーティションキーを構成します。 範囲パーティションを使うときは、パーティションキーは複数の列または式にまたがることができます(最大で32ですが、この制限はPostgreSQLをビルドする時に変更できます)が、リストパーティションでは、パーティションキーは1つだけの列または式で構成されなければなりません。 パーティションテーブルの作成時にBツリー演算子クラスを指定しない場合は、そのデータ型のデフォルトのBツリー演算子クラスが使用されます。 Bツリー演算子クラスがない場合はエラーが報告されます。

Range and list partitioning require a btree operator class, while hash partitioning requires a hash operator class. If no operator class is specified explicitly, the default operator class of the appropriate type will be used; if no default operator class exists, an error will be raised. When hash partitioning is used, the operator class used must implement support function 2 (see <xref linkend="xindex-support"/> for details). 範囲とリストのパーティショニングはBツリー演算子クラスを必要とし、ハッシュパーティショニングはハッシュ演算子クラスを必要とします。 演算子クラスが明示的に指定されない場合、適当な型のデフォルトの演算子クラスが使われます。デフォルト演算子クラスがなければエラーが発生します。 ハッシュパーティショニングが使われているとき、使われる演算子クラスはサポート関数2を実装していなければなりません(詳しくは38.16.3を参照)。

A partitioned table is divided into sub-tables (called partitions), which are created using separate <literal>CREATE TABLE</literal> commands. The partitioned table is itself empty. A data row inserted into the table is routed to a partition based on the value of columns or expressions in the partition key. If no existing partition matches the values in the new row, an error will be reported. パーティションテーブルは(パーティションと呼ばれる)副テーブルに分割され、それらは別のCREATE TABLEコマンドにより作成されます。 パーティションテーブルそれ自体は空になります。 テーブルに挿入されるデータ行は、パーティションキーの列あるいは式の値に基づいて、1つのパーティションに回されます。 新しい行の値に適合するパーティションが存在しないときは、エラーが報告されます。

Partitioned tables do not support <literal>EXCLUDE</literal> constraints; however, you can define these constraints on individual partitions. パーティションテーブルはEXCLUDE制約をサポートしません。しかしながら、個々のパーティションにこの制約を定義することはできます。

See <xref linkend="ddl-partitioning"/> for more discussion on table partitioning. テーブルパーティショニングに関するより詳しい議論は5.11を参照してください。

PARTITION OF parent_table { FOR VALUES partition_bound_spec | DEFAULT } #

Creates the table as a <firstterm>partition</firstterm> of the specified parent table. The table can be created either as a partition for specific values using <literal>FOR VALUES</literal> or as a default partition using <literal>DEFAULT</literal>. Any indexes, constraints and user-defined row-level triggers that exist in the parent table are cloned on the new partition. 指定した親テーブルのパーティションとしてテーブルを作成します。 FOR VALUESを用いて特定の値のパーティションとして、あるいは、DEFAULTを用いてデフォルトパーティションとしてテーブルを作成できます。 親テーブルにあるインデックス、制約、ユーザ定義の行レベルのトリガは新しいパーティションに複製されます。

The <replaceable class="parameter">partition_bound_spec</replaceable> must correspond to the partitioning method and partition key of the parent table, and must not overlap with any existing partition of that parent. The form with <literal>IN</literal> is used for list partitioning, the form with <literal>FROM</literal> and <literal>TO</literal> is used for range partitioning, and the form with <literal>WITH</literal> is used for hash partitioning. partition_bound_specは親テーブルのパーティショニング方法とパーティションキーに対応していなければならず、またそのテーブルのどの既存のパーティションとも重なり合ってはいけません。 INの構文はリストパーティショニングで、FROMTOの構文は範囲パーティショニングで、WITHの構文はハッシュパーティショニングで、使用されます。

<replaceable class="parameter">partition_bound_expr</replaceable> is any variable-free expression (subqueries, window functions, aggregate functions, and set-returning functions are not allowed). Its data type must match the data type of the corresponding partition key column. The expression is evaluated once at table creation time, so it can even contain volatile expressions such as <literal><function>CURRENT_TIMESTAMP</function></literal>. partition_bound_exprは任意の無変数式です(サブクエリ、ウィンドウ関数、集約関数、複数行を返す関数は許されません)。 式のデータ型は対応するパーティションキー列と一致しなければなりません。 式はテーブル作成時に一度だけ評価されるため、CURRENT_TIMESTAMPなどの揮発性の式を含むことも可能です。

When creating a list partition, <literal>NULL</literal> can be specified to signify that the partition allows the partition key column to be null. However, there cannot be more than one such list partition for a given parent table. <literal>NULL</literal> cannot be specified for range partitions. リストパーティションを作るときは、NULLを指定することができて、それはそのパーティションではパーティションキーの列をNULLにすることができるということを意味します。 しかし、1つの親テーブルで2つ以上、そのようなリストパーティションを作ることはできません。 範囲パーティションではNULLを指定することはできません。

When creating a range partition, the lower bound specified with <literal>FROM</literal> is an inclusive bound, whereas the upper bound specified with <literal>TO</literal> is an exclusive bound. That is, the values specified in the <literal>FROM</literal> list are valid values of the corresponding partition key columns for this partition, whereas those in the <literal>TO</literal> list are not. Note that this statement must be understood according to the rules of row-wise comparison (<xref linkend="row-wise-comparison"/>). For example, given <literal>PARTITION BY RANGE (x,y)</literal>, a partition bound <literal>FROM (1, 2) TO (3, 4)</literal> allows <literal>x=1</literal> with any <literal>y&gt;=2</literal>, <literal>x=2</literal> with any non-null <literal>y</literal>, and <literal>x=3</literal> with any <literal>y&lt;4</literal>. 範囲パーティションを作るとき、FROMで指定する下限はそれを含む境界、TOで指定する上限はそれを含まない境界になります。 つまり、FROMリストで指定される値は、そのパーティションの対応するパーティションキー列において有効な値ですが、TOリストで指定される値はそうではない、ということです。 この文の意味は行単位の比較の規則(9.24.5)に従って理解しなければならないことに注意してください。 例えば、PARTITION BY RANGE (x,y)について、パーティション境界FROM (1, 2) TO (3, 4)には、x=1y>=2の任意の値のもの、x=2でNULLでない任意のyのもの、x=3y<4の任意の値のものが入ります。

The special values <literal>MINVALUE</literal> and <literal>MAXVALUE</literal> may be used when creating a range partition to indicate that there is no lower or upper bound on the column's value. For example, a partition defined using <literal>FROM (MINVALUE) TO (10)</literal> allows any values less than 10, and a partition defined using <literal>FROM (10) TO (MAXVALUE)</literal> allows any values greater than or equal to 10. 範囲パーティションを作るとき、MINVALUEおよびMAXVALUEという特別な値を使用することができて、これらはそれぞれ列の値に下限と上限がないことを示します。 例えば、FROM (MINVALUE) TO (10)で定義されたパーティションには10より小さいすべての値が入り、FROM (10) TO (MAXVALUE)で定義されたパーティションには10以上のすべての値が入ります。

When creating a range partition involving more than one column, it can also make sense to use <literal>MAXVALUE</literal> as part of the lower bound, and <literal>MINVALUE</literal> as part of the upper bound. For example, a partition defined using <literal>FROM (0, MAXVALUE) TO (10, MAXVALUE)</literal> allows any rows where the first partition key column is greater than 0 and less than or equal to 10. Similarly, a partition defined using <literal>FROM ('a', MINVALUE) TO ('b', MINVALUE)</literal> allows any rows where the first partition key column starts with "a". 2つ以上の列を含む範囲パーティションを作るとき、MAXVALUEを下限の一部として使うことや、MINVALUEを上限の一部として使うことも意味を持ちえます。 例えば、FROM (0, MAXVALUE) TO (10, MAXVALUE)で定義されたパーティションには、パーティションキーの第1列が0より大きく、かつ10以下であるものが入ります。 同様に、FROM ('a', MINVALUE) TO ('b', MINVALUE)で定義されたパーティションには、パーティションキーの第1列が"a"で始まるすべての行が入ります。

Note that if <literal>MINVALUE</literal> or <literal>MAXVALUE</literal> is used for one column of a partitioning bound, the same value must be used for all subsequent columns. For example, <literal>(10, MINVALUE, 0)</literal> is not a valid bound; you should write <literal>(10, MINVALUE, MINVALUE)</literal>. MINVALUEまたはMAXVALUEをパーティション境界の1つの列で使用する場合、それより後の列では同じ値を使用しなければならないことに注意してください。 例えば、(10, MINVALUE, 0)は有効な境界ではありません。 (10, MINVALUE, MINVALUE)とします。

Also note that some element types, such as <literal>timestamp</literal>, have a notion of "infinity", which is just another value that can be stored. This is different from <literal>MINVALUE</literal> and <literal>MAXVALUE</literal>, which are not real values that can be stored, but rather they are ways of saying that the value is unbounded. <literal>MAXVALUE</literal> can be thought of as being greater than any other value, including "infinity" and <literal>MINVALUE</literal> as being less than any other value, including "minus infinity". Thus the range <literal>FROM ('infinity') TO (MAXVALUE)</literal> is not an empty range; it allows precisely one value to be stored &mdash; "infinity". timestamp,など一部の要素型では、"infinity"(無限)の概念があり、それも保存できる値であることにも注意してください。 MINVALUEMAXVALUEは保存できる真の値ではなく、値に境界がないということを表現するための方法に過ぎないため、これとは違います。 MAXVALUEは"infinity"も含め、他のすべての値より大きいものと考えることができ、またMINVALUEは"minus infinity"も含め、他のすべての値より小さいものと考えることができます。 従って、境界FROM ('infinity') TO (MAXVALUE)は空の範囲ではなく、たった1つの値、つまり"infinity"だけを保存します。

If <literal>DEFAULT</literal> is specified, the table will be created as the default partition of the parent table. This option is not available for hash-partitioned tables. A partition key value not fitting into any other partition of the given parent will be routed to the default partition. DEFAULTが指定された場合、テーブルは親テーブルのデフォルトパーティションとして作成されます。 本オプションはハッシュパーティションされたテーブルには使用できません。 親の他のどのパーティションにも当てはまらないパーティションキー値はデフォルトパーティションに送られます。

When a table has an existing <literal>DEFAULT</literal> partition and a new partition is added to it, the default partition must be scanned to verify that it does not contain any rows which properly belong in the new partition. If the default partition contains a large number of rows, this may be slow. The scan will be skipped if the default partition is a foreign table or if it has a constraint which proves that it cannot contain rows which should be placed in the new partition. テーブルが既存のDEFAULTパーティションを持っていて、新たなパーティションが追加された場合、デフォルトパーティションは、新たなパーティションに属すのがふさわしい行が含まれていないことを確かめるために、検査されなければなりません。 デフォルトパーティションに多数の行が含まれている場合、これは時間を要すかもしれません。 デフォルトパーティションが、外部テーブルであるか、新パーティションに置くべき行を含むことができないことを証明する制約を持つ場合、この検査は省略されます。

When creating a hash partition, a modulus and remainder must be specified. The modulus must be a positive integer, and the remainder must be a non-negative integer less than the modulus. Typically, when initially setting up a hash-partitioned table, you should choose a modulus equal to the number of partitions and assign every table the same modulus and a different remainder (see examples, below). However, it is not required that every partition have the same modulus, only that every modulus which occurs among the partitions of a hash-partitioned table is a factor of the next larger modulus. This allows the number of partitions to be increased incrementally without needing to move all the data at once. For example, suppose you have a hash-partitioned table with 8 partitions, each of which has modulus 8, but find it necessary to increase the number of partitions to 16. You can detach one of the modulus-8 partitions, create two new modulus-16 partitions covering the same portion of the key space (one with a remainder equal to the remainder of the detached partition, and the other with a remainder equal to that value plus 8), and repopulate them with data. You can then repeat this &#45;- perhaps at a later time &#45;- for each modulus-8 partition until none remain. While this may still involve a large amount of data movement at each step, it is still better than having to create a whole new table and move all the data at once. ハッシュパーティションを作るときには法と残余を指定しなければなりません。 法は正の整数でなければならず、残余は法よりも小さい非負整数でなければなりません。 典型的にはハッシュパーティションテーブル初期設定をするとき、パーティションの数と等しい法を選び、全てのテーブルに同じ法と異なる残余を割り当てます(後述の例を参照)。 しかしながら、全てのパーティションが同じ法を持つ必要はなく、あるハッシュパーティションテーブルのパーティションに存在する全ての法が次に大きい法の因子であることだけ必要です。 このことは、全データを一度に移すことなくパーティション数を徐々に増やすことを可能にします。 例えば、各々の法が8である8パーティションのハッシュパーティションテーブルがあるとして、パーティション数を16に増やさなければならなくなったとします。 私たちは8を法とするパーティションの一つをデタッチして、新たに16を法とするキー空間の同じ部分(一つはデタッチしたパーティションと等しい残余を持ち、一つはその値に8を加えたのと等しい残余を持つ)を対象とする二つのパーティションを追加して、データを再配置することができます。 これを(おそらくはより後に)8を法とする各パーティションがなくなるまで、繰り返すことができます。 これは依然として各ステップで大きなデータ移動を伴いますが、全体の新テーブルを作って全データを一度に移さなければならないというよりは、まだ良いです。

A partition must have the same column names and types as the partitioned table to which it belongs. Modifications to the column names or types of a partitioned table will automatically propagate to all partitions. <literal>CHECK</literal> constraints will be inherited automatically by every partition, but an individual partition may specify additional <literal>CHECK</literal> constraints; additional constraints with the same name and condition as in the parent will be merged with the parent constraint. Defaults may be specified separately for each partition. But note that a partition's default value is not applied when inserting a tuple through a partitioned table. パーティションは、それが属するパーティションテーブルと同じ列名および型を持っていなければなりません。 パーティションテーブルの列名や型の変更は自動的にすべてのパーティションに反映されます。 CHECK制約はすべてのパーティションで自動的に継承されますが、個々のパーティションで追加のCHECK制約を指定することができます。 親の制約と同じ名前と条件を持つ追加制約は親の制約と統合されます。 デフォルト制約は各パーティションで別々に指定できます。 ですが、パーティションのデフォルト値は、パーティションテーブルを通してタプルを挿入する場合には適用されないことに注意してください。

Rows inserted into a partitioned table will be automatically routed to the correct partition. If no suitable partition exists, an error will occur. パーティションテーブルに挿入された行は、自動的に正しいパーティションに回されます。 適当なパーティションが存在しないときは、エラーが発生します。

Operations such as <command>TRUNCATE</command> which normally affect a table and all of its inheritance children will cascade to all partitions, but may also be performed on an individual partition. TRUNCATEのように通常はテーブルとそれを継承するすべての子テーブルに影響を及ぼす操作は、すべてのパーティションに対しても適用されますが、個別のパーティションに対して操作することも可能です。

Note that creating a partition using <literal>PARTITION OF</literal> requires taking an <literal>ACCESS EXCLUSIVE</literal> lock on the parent partitioned table. Likewise, dropping a partition with <command>DROP TABLE</command> requires taking an <literal>ACCESS EXCLUSIVE</literal> lock on the parent table. It is possible to use <link linkend="sql-altertable"><command>ALTER TABLE ATTACH/DETACH PARTITION</command></link> to perform these operations with a weaker lock, thus reducing interference with concurrent operations on the partitioned table. PARTITION OFを使用してパーティションを作成するには、親のパーティション化されたテーブルでACCESS EXCLUSIVEロックを取得する必要があることに注意してください。 同様に、DROP TABLEでパーティションを削除するには、親テーブルについてACCESS EXCLUSIVEロックを取得する必要があります。 パーティション化されたテーブルでの同時操作による干渉を減らし、より弱いロックでこれらの操作を実行するため、ALTER TABLE ATTACH/DETACH PARTITIONを使用できます。

LIKE source_table [ like_option ... ] #

The <literal>LIKE</literal> clause specifies a table from which the new table automatically copies all column names, their data types, and their not-null constraints. LIKE句にテーブルを指定すると、自動的にそのテーブルの全ての列名、そのデータ型、非NULL制約が新しいテーブルにコピーされます。

Unlike <literal>INHERITS</literal>, the new table and original table are completely decoupled after creation is complete. Changes to the original table will not be applied to the new table, and it is not possible to include data of the new table in scans of the original table. INHERITSとは違い、作成した後、新しいテーブルと元のテーブルが完全に分離されます。 元のテーブルへの変更は新しいテーブルには適用されません。また、元のテーブルを走査しても新しいテーブルのデータは見つかりません。

Also unlike <literal>INHERITS</literal>, columns and constraints copied by <literal>LIKE</literal> are not merged with similarly named columns and constraints. If the same name is specified explicitly or in another <literal>LIKE</literal> clause, an error is signaled. INHERITSと異なり、LIKEによりコピーされた列や制約は類似の名前の列や制約にまとめられません。 同じ名前が明示的に、あるいは他のLIKE句で指定された場合、エラーが通知されます。

The optional <replaceable>like_option</replaceable> clauses specify which additional properties of the original table to copy. Specifying <literal>INCLUDING</literal> copies the property, specifying <literal>EXCLUDING</literal> omits the property. <literal>EXCLUDING</literal> is the default. If multiple specifications are made for the same kind of object, the last one is used. The available options are: オプションのlike_option句は元テーブルのどの追加属性をコピーするかを指定します。 INCLUDING指定は属性をコピーし、EXCLUDING指定は属性を省きます。 EXCLUDINGがデフォルトです。 同種の対象に複数の指定がある場合には最後のものが使われます。 指定可能なオプションは以下です。

INCLUDING COMMENTS #

Comments for the copied columns, constraints, and indexes will be copied. The default behavior is to exclude comments, resulting in the copied columns and constraints in the new table having no comments. コピーされた列、制約、および、インデックスに対するコメントがコピーされます。 デフォルトの振る舞いではコメントは除外されて、新しいテーブルのコピーされた列と制約にはコメントがありません。

INCLUDING COMPRESSION #

Compression method of the columns will be copied. The default behavior is to exclude compression methods, resulting in columns having the default compression method. 列の圧縮法をコピーします。 デフォルトの振る舞いでは圧縮法は除外されて、列にはデフォルトの圧縮法が設定されます。

INCLUDING CONSTRAINTS #

<literal>CHECK</literal> constraints will be copied. No distinction is made between column constraints and table constraints. Not-null constraints are always copied to the new table. CHECK制約がコピーされます。 列制約とテーブル制約の区別はされません。 非NULL制約は常に新しいテーブルにコピーされます。

INCLUDING DEFAULTS #

Default expressions for the copied column definitions will be copied. Otherwise, default expressions are not copied, resulting in the copied columns in the new table having null defaults. Note that copying defaults that call database-modification functions, such as <function>nextval</function>, may create a functional linkage between the original and new tables. コピーされた列定義に対するデフォルト式をコピーします。 この指定が無い場合、デフォルト式はコピーされず、新しいテーブルのコピーされた列はNULLのデフォルトとなります。 nextvalなどのデータベースを変更する関数を呼び出すデフォルトのコピーは、元のテーブルと新しいテーブルの間で関数の連鎖を引き起こすかもしれないことに注意してください。

INCLUDING GENERATED #

Any generation expressions of copied column definitions will be copied. By default, new columns will be regular base columns. コピーされた列定義の全ての生成式がコピーされます。 デフォルトでは新たな列は通常の基底列となります。

INCLUDING IDENTITY #

Any identity specifications of copied column definitions will be copied. A new sequence is created for each identity column of the new table, separate from the sequences associated with the old table. コピーされた列定義の全てのアイデンティティ指定がコピーされます。 新しいテーブルの各識別列に対して新たなシーケンスが作られ、旧テーブルに関連付けられたシーケンスとは分離されます。

INCLUDING INDEXES #

Indexes, <literal>PRIMARY KEY</literal>, <literal>UNIQUE</literal>, and <literal>EXCLUDE</literal> constraints on the original table will be created on the new table. Names for the new indexes and constraints are chosen according to the default rules, regardless of how the originals were named. (This behavior avoids possible duplicate-name failures for the new indexes.) 元テーブルのインデックス、および、PRIMARY KEYUNIQUEEXCLUDE制約が新しいテーブルに作成されます。 新しいインデックスと制約の名前はデフォルトの規則に従って決められ、元テーブルでのどう名前付けされているかは考慮されません。 (この振る舞いは新しいインデックスでの起こりうる名前重複エラーを回避します。)

INCLUDING STATISTICS #

Extended statistics are copied to the new table. 拡張統計情報が新しいテーブルにコピーされます。

INCLUDING STORAGE #

<literal>STORAGE</literal> settings for the copied column definitions will be copied. The default behavior is to exclude <literal>STORAGE</literal> settings, resulting in the copied columns in the new table having type-specific default settings. For more on <literal>STORAGE</literal> settings, see <xref linkend="storage-toast"/>. コピーされた列定義に対するSTORAGE設定がコピーされます。 デフォルトの振る舞いではSTORAGE設定は除外され、そのため新しいテーブルのコピーされた列はデータ型ごとのデフォルト設定を持ちます。 STORAGE設定に関する詳細は73.2を参照してください。

INCLUDING ALL #

<literal>INCLUDING ALL</literal> is an abbreviated form selecting all the available individual options. (It could be useful to write individual <literal>EXCLUDING</literal> clauses after <literal>INCLUDING ALL</literal> to select all but some specific options.) INCLUDING ALLは全ての各オプションを選択することの短縮形式です。 (一部オプションを除き全てを選択するために、個別のEXCLUDING句をINCLUDING ALLの後に書く場合におそらく有益です。)

The <literal>LIKE</literal> clause can also be used to copy column definitions from views, foreign tables, or composite types. Inapplicable options (e.g., <literal>INCLUDING INDEXES</literal> from a view) are ignored. またLIKE句をビュー、外部テーブル、複合型から列の定義をコピーするために使用することができます。 適用できないオプション(ビューからのINCLUDING INDEXESなど)は無視されます。

CONSTRAINT constraint_name #

An optional name for a column or table constraint. If the constraint is violated, the constraint name is present in error messages, so constraint names like <literal>col must be positive</literal> can be used to communicate helpful constraint information to client applications. (Double-quotes are needed to specify constraint names that contain spaces.) If a constraint name is not specified, the system generates a name. 列制約、テーブル制約の名前(省略可能)です。 制約に違反すると、制約名がエラーメッセージに含まれます。 ですので、col must be positive(正数でなければならない)といった名前の制約名を付与することで、クライアントアプリケーションへ有用な制約情報を渡すことができます。 (空白を含む制約名を指定する場合、二重引用符が必要です。) 指定されなければ、システムが名前を生成します。

NOT NULL #

The column is not allowed to contain null values. その列がNULL値を持てないことを指定します。

NULL #

The column is allowed to contain null values. This is the default. その列がNULL値を持てることを指定します。 これがデフォルトです。

This clause is only provided for compatibility with non-standard SQL databases. Its use is discouraged in new applications. この句は非標準的なSQLデータベースとの互換性のためだけに提供されています。 新しいアプリケーションでこれを使用するのはお勧めしません。

CHECK ( expression ) [ NO INHERIT ] #

The <literal>CHECK</literal> clause specifies an expression producing a Boolean result which new or updated rows must satisfy for an insert or update operation to succeed. Expressions evaluating to TRUE or UNKNOWN succeed. Should any row of an insert or update operation produce a FALSE result, an error exception is raised and the insert or update does not alter the database. A check constraint specified as a column constraint should reference that column's value only, while an expression appearing in a table constraint can reference multiple columns. CHECK句は、論理型の結果を生成する、新しい行または更新される行が挿入または更新処理を成功させるために満足しなければならない式を指定します。 TRUEまたはUNKNOWNと評価される式は成功します。 挿入または更新処理の行がFALSEという結果をもたらす場合はエラー例外が発生し、その挿入または更新によるデータベースの変更は行われません。 列制約として指定された検査制約は列の値のみを参照しなければなりません。 テーブル制約内の式は複数の列を参照できます。

Currently, <literal>CHECK</literal> expressions cannot contain subqueries nor refer to variables other than columns of the current row (see <xref linkend="ddl-constraints-check-constraints"/>). The system column <literal>tableoid</literal> may be referenced, but not any other system column. 現時点では、CHECK式には副問い合わせも現在の行の列以外の変数も含めることはできません(5.4.1を参照)。 システム列tableoidを参照することはできますが、他のシステム列は参照できません。

A constraint marked with <literal>NO INHERIT</literal> will not propagate to child tables. NO INHERITと印が付いた制約は子テーブルには伝搬しません。

When a table has multiple <literal>CHECK</literal> constraints, they will be tested for each row in alphabetical order by name, after checking <literal>NOT NULL</literal> constraints. (<productname>PostgreSQL</productname> versions before 9.5 did not honor any particular firing order for <literal>CHECK</literal> constraints.) テーブルに複数のCHECK制約がある場合、それらはNOT NULL制約について検証した後で、各行について名前のアルファベット順に検証されます。 (PostgreSQLの9.5より前のバージョンでは、CHECK制約の実行について特定の順序はありませんでした。)

DEFAULT default_expr #

The <literal>DEFAULT</literal> clause assigns a default data value for the column whose column definition it appears within. The value is any variable-free expression (in particular, cross-references to other columns in the current table are not allowed). Subqueries are not allowed either. The data type of the default expression must match the data type of the column. DEFAULT句を列定義に付けると、その列にデフォルトデータ値が割り当てられます。 値として指定するのは任意の無変数式です(特に現在のテーブル内の他の列へクロス参照はできません)。 副問い合わせも指定できません。 デフォルト式のデータ型はその列のデータ型と一致する必要があります。

The default expression will be used in any insert operation that does not specify a value for the column. If there is no default for a column, then the default is null. デフォルト式は、全ての挿入操作において、その列に値が指定されていない場合に使用されます。 列にデフォルト値がない場合、デフォルト値はNULLになります。

GENERATED ALWAYS AS ( generation_expr ) STORED #

This clause creates the column as a <firstterm>generated column</firstterm>. The column cannot be written to, and when read the result of the specified expression will be returned. この句は列を生成列として作成します。 この列には書き込みできず、読むときには指定された式の結果が返されます。

The keyword <literal>STORED</literal> is required to signify that the column will be computed on write and will be stored on disk. キーワードSTOREDは列が書き込み時に計算されてディスクに格納されることをあらわすのに必要とされます。

The generation expression can refer to other columns in the table, but not other generated columns. Any functions and operators used must be immutable. References to other tables are not allowed. 生成式はそのテーブルの他の列を参照できますが、他の生成列は参照できません。 使われる全ての関数と演算子はIMMUTABLEでなければなりません。 他テーブルを参照することはできません。

GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ( sequence_options ) ] #

This clause creates the column as an <firstterm>identity column</firstterm>. It will have an implicit sequence attached to it and the column in new rows will automatically have values from the sequence assigned to it. Such a column is implicitly <literal>NOT NULL</literal>. この句は列をIDENTITY列として作成します。 それには暗黙のシーケンスが紐付けられ、新しい行のその列には紐付けられたシーケンスから取られた値が自動的に入ります。 そのような列は暗黙的にNOT NULLです。

The clauses <literal>ALWAYS</literal> and <literal>BY DEFAULT</literal> determine how explicitly user-specified values are handled in <command>INSERT</command> and <command>UPDATE</command> commands. ALWAYSBY DEFAULTの句は、INSERTUPDATEコマンドで明示的にユーザが指定した値をどのように扱うかを決定します。

In an <command>INSERT</command> command, if <literal>ALWAYS</literal> is selected, a user-specified value is only accepted if the <command>INSERT</command> statement specifies <literal>OVERRIDING SYSTEM VALUE</literal>. If <literal>BY DEFAULT</literal> is selected, then the user-specified value takes precedence. See <xref linkend="sql-insert"/> for details. (In the <command>COPY</command> command, user-specified values are always used regardless of this setting.) INSERTコマンドでは、ALWAYSが選択された場合、ユーザの指定した値はINSERT文がOVERRIDING SYSTEM VALUEを指定している場合にのみ受け付けられます。 BY DEFAULTが選択された場合、ユーザの指定した値が優先します。 詳細はINSERTを参照してください。 (COPYコマンドでは、この設定に関係なく、ユーザの指定した値が常に使われます。)

In an <command>UPDATE</command> command, if <literal>ALWAYS</literal> is selected, any update of the column to any value other than <literal>DEFAULT</literal> will be rejected. If <literal>BY DEFAULT</literal> is selected, the column can be updated normally. (There is no <literal>OVERRIDING</literal> clause for the <command>UPDATE</command> command.) UPDATEでは、ALWAYSが選択された場合、DEFAULT以外の値への列の更新は拒絶されます。 BY DEFAULTが選択された場合、列は普通に更新されます。 (UPDATEコマンドにOVERRIDING句はありません。)

The optional <replaceable>sequence_options</replaceable> clause can be used to override the options of the sequence. See <xref linkend="sql-createsequence"/> for details. オプションでsequence_options句を指定することにより、シーケンスのオプションを変更できます。 詳しくはCREATE SEQUENCEを参照してください。

UNIQUE [ NULLS [ NOT ] DISTINCT ] (列制約)
UNIQUE [ NULLS [ NOT ] DISTINCT ] ( column_name [, ... ] ) <optional> <literal>INCLUDE ( <replaceable class="parameter">column_name</replaceable> [, ...])</literal> </optional> (table constraint)</term> [ INCLUDE ( column_name [, ...]) ] (テーブル制約) #

The <literal>UNIQUE</literal> constraint specifies that a group of one or more columns of a table can contain only unique values. The behavior of a unique table constraint is the same as that of a unique column constraint, with the additional capability to span multiple columns. The constraint therefore enforces that any two rows must differ in at least one of these columns. UNIQUE制約は、テーブルの1つまたは複数の列からなるグループが、一意な値のみを持つことができることを指定します。 一意性テーブル制約の動作は一意性列制約と同じですが、さらに複数列にまたがる機能を持ちます。 それゆえ、制約は2つの行はその列の少なくとも1つが異なることを強制します。

For the purpose of a unique constraint, null values are not considered equal, unless <literal>NULLS NOT DISTINCT</literal> is specified. 一意性制約では、NULLS NOT DISTINCTが指定されない限り、NULL値同士は等しいとはみなされなせん。

Each unique constraint should name a set of columns that is different from the set of columns named by any other unique or primary key constraint defined for the table. (Otherwise, redundant unique constraints will be discarded.) それぞれの一意性制約には、そのテーブルの他の一意性制約もしくは主キー制約によって指定された列の集合とは、異なる列の集合を指定しなければなりません。 (そうでなければ、余分な一意性制約は捨てられます。)

When establishing a unique constraint for a multi-level partition hierarchy, all the columns in the partition key of the target partitioned table, as well as those of all its descendant partitioned tables, must be included in the constraint definition. 複数レベルのパーティション階層に一意性制約を設定するとき、対象パーティションテーブル、および全ての子孫のパーティションテーブルの、パーティションキー内の全ての列が制約定義に含まれなくてはなりません。

Adding a unique constraint will automatically create a unique btree index on the column or group of columns used in the constraint. 一意性制約を加えると、制約で使われている列や列のグループに一意性btreeインデックスが自動的に作られます。

The optional <literal>INCLUDE</literal> clause adds to that index one or more columns that are simply <quote>payload</quote>: uniqueness is not enforced on them, and the index cannot be searched on the basis of those columns. However they can be retrieved by an index-only scan. Note that although the constraint is not enforced on included columns, it still depends on them. Consequently, some operations on such columns (e.g., <literal>DROP COLUMN</literal>) can cause cascaded constraint and index deletion. 省略可能なINCLUDE句はインデックスに単にペイロードである列を1つまたは複数、追加します。一意性はその列には強要されず、その列に基づいてインデックスが検索されることはありません。 しかしながら、インデックスオンリースキャンでは取り出すことができます。 含めた(INCLUDEした)列に制約は強制されませんが、依存はしていることに注意してください。 このため、これらの列に対する一部の操作(例えばDROP COLUMN)は制約の連鎖とインデックスの削除をひき起こすことがあります。

PRIMARY KEY (列制約)
PRIMARY KEY ( column_name [, ... ] ) <optional> <literal>INCLUDE ( <replaceable class="parameter">column_name</replaceable> [, ...])</literal> </optional> (table constraint)</term> [ INCLUDE ( column_name [, ...]) ] (テーブル制約) #

The <literal>PRIMARY KEY</literal> constraint specifies that a column or columns of a table can contain only unique (non-duplicate), nonnull values. Only one primary key can be specified for a table, whether as a column constraint or a table constraint. PRIMARY KEY制約はテーブルの一列または複数の列が一意(重複がない)で、非NULLの値のみを持つことを指定します。 列制約かテーブル制約かに関わらず、1つのテーブルには主キーを1つだけ指定できます。

The primary key constraint should name a set of columns that is different from the set of columns named by any unique constraint defined for the same table. (Otherwise, the unique constraint is redundant and will be discarded.) 主キー制約では、同じテーブルに一意制約で指定した列の集合とは異なる列の集合を指定します。 (そうでなければ、一意制約は冗長となり、捨てられます。)

<literal>PRIMARY KEY</literal> enforces the same data constraints as a combination of <literal>UNIQUE</literal> and <literal>NOT NULL</literal>. However, identifying a set of columns as the primary key also provides metadata about the design of the schema, since a primary key implies that other tables can rely on this set of columns as a unique identifier for rows. PRIMARY KEYUNIQUENOT NULLの組み合わせと同じデータ制約を課します。 ですが、列の集合を主キーと指定することは、スキーマの設計についてのメタデータを提供することにもなります。 なぜなら、主キーであることは、行を一意に特定するものとして、他のテーブルがその列の集合を当てにして良い、ということを意味するからです。

When placed on a partitioned table, <literal>PRIMARY KEY</literal> constraints share the restrictions previously described for <literal>UNIQUE</literal> constraints. パーティションテーブルに設定すると、PRIMARY KEY制約は、以前述べた制限をUNIQUE制約と共有します。

Adding a <literal>PRIMARY KEY</literal> constraint will automatically create a unique btree index on the column or group of columns used in the constraint. PRIMARY KEY制約を追加すると、制約で使用する列や列のグループに一意性のbtreeインデックスが自動的に作られます。

The optional <literal>INCLUDE</literal> clause adds to that index one or more columns that are simply <quote>payload</quote>: uniqueness is not enforced on them, and the index cannot be searched on the basis of those columns. However they can be retrieved by an index-only scan. Note that although the constraint is not enforced on included columns, it still depends on them. Consequently, some operations on such columns (e.g., <literal>DROP COLUMN</literal>) can cause cascaded constraint and index deletion. 省略可能なINCLUDE句はインデックスに単にペイロードである列を1つまたは複数、追加します。一意性はその列には強要されず、その列に基づいてインデックスが検索されることはありません。 しかしながら、インデックスオンリースキャンでは取り出すことができます。 含めた列に一意性は強制されませんが、制約はこれらに依存はしています。 このため、これらの列に対する一部の操作(例えばDROP COLUMN)は制約の連鎖とインデックスの削除をひき起こすことがあります。

EXCLUDE [ USING index_method ] ( exclude_element WITH operator [, ... ] ) index_parameters [ WHERE ( predicate ) ] #

The <literal>EXCLUDE</literal> clause defines an exclusion constraint, which guarantees that if any two rows are compared on the specified column(s) or expression(s) using the specified operator(s), not all of these comparisons will return <literal>TRUE</literal>. If all of the specified operators test for equality, this is equivalent to a <literal>UNIQUE</literal> constraint, although an ordinary unique constraint will be faster. However, exclusion constraints can specify constraints that are more general than simple equality. For example, you can specify a constraint that no two rows in the table contain overlapping circles (see <xref linkend="datatype-geometric"/>) by using the <literal>&amp;&amp;</literal> operator. EXCLUDE句は排他制約を定義し、任意の2行について指定した列(複数可)または式(複数可)を指定した演算子(複数可)を使用して比較した場合、比較結果のすべてがTRUEを返さないことを保証します。 指定した演算子のすべてが等価性を試験するものであれば、これはUNIQUE制約と同じですが、通常の一意性制約のほうが高速です。 しかし、排他制約では単純な等価性よりも一般的な制約を指定することができます。 例えば、テーブル内の2つの行が重複する円(8.8参照)を持たないといった制約を&&演算子を使用して指定することができます。

Exclusion constraints are implemented using an index, so each specified operator must be associated with an appropriate operator class (see <xref linkend="indexes-opclass"/>) for the index access method <replaceable>index_method</replaceable>. The operators are required to be commutative. Each <replaceable class="parameter">exclude_element</replaceable> can optionally specify an operator class and/or ordering options; these are described fully under <xref linkend="sql-createindex"/>. 排他制約はインデックスを使用して実装されています。 このため指定した演算子はそれぞれ適切な演算子クラス(11.10参照)でindex_methodインデックスアクセスメソッドと関連付けされていなければなりません。 演算子は交換可能でなければなりません。 オプションで、各exclude_elementは演算子クラス、順序付けオプション、またはその両方を指定することができます。 これらについてはCREATE INDEXで説明します。

The access method must support <literal>amgettuple</literal> (see <xref linkend="indexam"/>); at present this means <acronym>GIN</acronym> cannot be used. Although it's allowed, there is little point in using B-tree or hash indexes with an exclusion constraint, because this does nothing that an ordinary unique constraint doesn't do better. So in practice the access method will always be <acronym>GiST</acronym> or <acronym>SP-GiST</acronym>. アクセスメソッドはamgettupleをサポートしなければなりません(第64章参照)。 現時点では、これはGINを使用できないことを意味します。 B-treeやHashインデックスを排他制約で使用することは許容されますが、そうすることにあまり意味はありません。 これが通常の一意性制約より良いことは何もないからです。 このため現実的にはアクセスメソッドは常にGiSTもしくはSP-GiSTとなります。

The <replaceable class="parameter">predicate</replaceable> allows you to specify an exclusion constraint on a subset of the table; internally this creates a partial index. Note that parentheses are required around the predicate. predicateにより、排他制約をテーブルの部分集合に指定することができます。 内部的には、これは部分インデックスを作成します。 predicateの前後に括弧が必要であることに注意して下さい。

REFERENCES reftable [ ( refcolumn ) ] [ MATCH matchtype ] [ ON DELETE action ] [ ON UPDATE action ] (列制約)
FOREIGN KEY ( column_name [, ... ] ) REFERENCES reftable [ ( refcolumn [, ... ] ) ] [ MATCH matchtype ] [ ON DELETE referential_action ] [ ON UPDATE referential_action ] (table constraint)</term> (表制約) #

These clauses specify a foreign key constraint, which requires that a group of one or more columns of the new table must only contain values that match values in the referenced column(s) of some row of the referenced table. If the <replaceable class="parameter">refcolumn</replaceable> list is omitted, the primary key of the <replaceable class="parameter">reftable</replaceable> is used. The referenced columns must be the columns of a non-deferrable unique or primary key constraint in the referenced table. The user must have <literal>REFERENCES</literal> permission on the referenced table (either the whole table, or the specific referenced columns). The addition of a foreign key constraint requires a <literal>SHARE ROW EXCLUSIVE</literal> lock on the referenced table. Note that foreign key constraints cannot be defined between temporary tables and permanent tables. これらの句は、外部キー制約を指定します。 外部キー制約は、新しいテーブルの1つまたは複数の列の集合が、被参照テーブルの一部の行の被参照列に一致する値を持たなければならないことを指定するものです。 refcolumnリストが省略された場合、reftableの主キーが使用されます。 被参照列は、被参照テーブルにおいて遅延不可の一意性制約もしくは主キー制約を持った列でなければなりません。 ユーザは被参照テーブル(テーブル全体または特定の被参照列)についてREFERENCES権限を持っていなければなりません。 外部キー制約の追加は被参照テーブルにSHARE ROW EXCLUSIVEロックを必要とします。 一時テーブルと永続テーブルとの間で外部キー制約を定義できないことに注意してください。

A value inserted into the referencing column(s) is matched against the values of the referenced table and referenced columns using the given match type. There are three match types: <literal>MATCH FULL</literal>, <literal>MATCH PARTIAL</literal>, and <literal>MATCH SIMPLE</literal> (which is the default). <literal>MATCH FULL</literal> will not allow one column of a multicolumn foreign key to be null unless all foreign key columns are null; if they are all null, the row is not required to have a match in the referenced table. <literal>MATCH SIMPLE</literal> allows any of the foreign key columns to be null; if any of them are null, the row is not required to have a match in the referenced table. <literal>MATCH PARTIAL</literal> is not yet implemented. (Of course, <literal>NOT NULL</literal> constraints can be applied to the referencing column(s) to prevent these cases from arising.) 参照列に挿入された値は、被参照テーブルと被参照列の値に対して、指定した照合型で照会されます。 照合型には3種類があります。 MATCH FULLMATCH PARTIALMATCH SIMPLE(これがデフォルト)照合型です。 MATCH FULLは全ての外部キー列がNULLとなる場合を除き、複数列外部キーのある列がNULLとなることを許可しません。 それらがすべてNULLであれば、その行は被参照テーブル内で一致があることは要求されません。 MATCH SIMPLEは、外部キーの一部がNULLであることを許可します。 それらの一部がNULLであれば、その行は被参照テーブル内で一致があることは要求されません。 MATCH PARTIALはまだ実装されていません。 (当然ですが、NOT NULL制約を参照列に適用し、こうした状態が発生することを防止することができます。)

In addition, when the data in the referenced columns is changed, certain actions are performed on the data in this table's columns. The <literal>ON DELETE</literal> clause specifies the action to perform when a referenced row in the referenced table is being deleted. Likewise, the <literal>ON UPDATE</literal> clause specifies the action to perform when a referenced column in the referenced table is being updated to a new value. If the row is updated, but the referenced column is not actually changed, no action is done. Referential actions other than the <literal>NO ACTION</literal> check cannot be deferred, even if the constraint is declared deferrable. There are the following possible actions for each clause: さらに、被参照列のデータが変更された場合、このテーブルの列のデータに何らかの動作が発生します。 ON DELETE句は、被参照テーブルの被参照行が削除されようとした場合の動作を指定します。 同様にON UPDATE句は、被参照テーブルの被参照列が新しい値に更新されようとした場合の動作を指定します。 行の更新があった場合でも、被参照列が実際に変更されない場合は、動作は実行されません。 制約が遅延可能と宣言されていても、NO ACTION検査以外の参照動作は遅延させられません。 各句について、以下の動作を指定可能です。

NO ACTION #

Produce an error indicating that the deletion or update would create a foreign key constraint violation. If the constraint is deferred, this error will be produced at constraint check time if there still exist any referencing rows. This is the default action. 削除もしくは更新により外部キー制約違反が起こることを示すエラーを発生します。 制約が遅延可能な場合、何らかの参照行が存在する限り、このエラーは制約の検査時点で発生します。 これはデフォルトの動作です。

RESTRICT #

Produce an error indicating that the deletion or update would create a foreign key constraint violation. This is the same as <literal>NO ACTION</literal> except that the check is not deferrable. 削除もしくは更新が外部キー制約違反となることを示すエラーを発生します。 検査が遅延できない点を除き、NO ACTIONと同じです。

CASCADE #

Delete any rows referencing the deleted row, or update the values of the referencing column(s) to the new values of the referenced columns, respectively. 削除された行を参照している行は全て削除します。また、参照している列の値を、被参照列の新しい値にします。

SET NULL [ ( column_name [, ... ] ) ] #

Set all of the referencing columns, or a specified subset of the referencing columns, to null. A subset of columns can only be specified for <literal>ON DELETE</literal> actions. すべての参照列または参照列の指定したサブセットをNULLに設定します。 列のサブセットは、ON DELETEアクションに対してのみ指定できます。

SET DEFAULT [ ( column_name [, ... ] ) ] #

Set all of the referencing columns, or a specified subset of the referencing columns, to their default values. A subset of columns can only be specified for <literal>ON DELETE</literal> actions. (There must be a row in the referenced table matching the default values, if they are not null, or the operation will fail.) すべての参照列または参照列の指定したサブセットをそのデフォルト値に設定します。 列のサブセットは、ON DELETEアクションに対してのみ指定できます。 (デフォルト値がNULLでない場合は被参照テーブルの中にデフォルト値に一致する行が存在しなければなりません。さもないと操作が失敗します。)

If the referenced column(s) are changed frequently, it might be wise to add an index to the referencing column(s) so that referential actions associated with the foreign key constraint can be performed more efficiently. 被参照列が頻繁に更新される場合、参照列にインデックスを付け、その外部キー制約に関連する参照動作がより効率的に実行できるようにする方が良いでしょう。

DEFERRABLE
NOT DEFERRABLE #

This controls whether the constraint can be deferred. A constraint that is not deferrable will be checked immediately after every command. Checking of constraints that are deferrable can be postponed until the end of the transaction (using the <link linkend="sql-set-constraints"><command>SET CONSTRAINTS</command></link> command). <literal>NOT DEFERRABLE</literal> is the default. Currently, only <literal>UNIQUE</literal>, <literal>PRIMARY KEY</literal>, <literal>EXCLUDE</literal>, and <literal>REFERENCES</literal> (foreign key) constraints accept this clause. <literal>NOT NULL</literal> and <literal>CHECK</literal> constraints are not deferrable. Note that deferrable constraints cannot be used as conflict arbitrators in an <command>INSERT</command> statement that includes an <literal>ON CONFLICT DO UPDATE</literal> clause. 制約を遅延させることが可能かどうかを制御します。 遅延不可の制約は各コマンドの後すぐに検査されます。 遅延可能な制約の検査は、(SET CONSTRAINTSコマンドを使用して)トランザクションの終了時まで遅延させることができます。 NOT DEFERRABLEがデフォルトです。 現在、UNIQUEPRIMARY KEYEXCLUDEREFERENCES(外部キー)制約のみがこの句を受け付けることができます。 NOT NULLおよび CHECK制約は遅延させることができません。 遅延可能な制約はON CONFLICT DO UPDATE句を含むINSERT文において、競合解決のために使うことはできないことに注意してください。

INITIALLY IMMEDIATE
INITIALLY DEFERRED #

If a constraint is deferrable, this clause specifies the default time to check the constraint. If the constraint is <literal>INITIALLY IMMEDIATE</literal>, it is checked after each statement. This is the default. If the constraint is <literal>INITIALLY DEFERRED</literal>, it is checked only at the end of the transaction. The constraint check time can be altered with the <link linkend="sql-set-constraints"><command>SET CONSTRAINTS</command></link> command. 制約が遅延可能な場合、この句は制約検査を行うデフォルトの時期を指定します。 制約がINITIALLY IMMEDIATEの場合、各文の実行後に検査されます。 これがデフォルトです。 制約がINITIALLY DEFERREDの場合、トランザクションの終了時にのみ検査されます。 制約検査の時期はSET CONSTRAINTSコマンドを使用して変更することができます。

USING method #

This optional clause specifies the table access method to use to store the contents for the new table; 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 table. 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 a table or index; see <xref linkend="sql-createtable-storage-parameters"/> below for more information. For backward-compatibility the <literal>WITH</literal> clause for a table can also include <literal>OIDS=FALSE</literal> to specify that rows of the new table should not contain OIDs (object identifiers), <literal>OIDS=TRUE</literal> is not supported anymore. この句はテーブルまたはインデックスに対するオプションの格納パラメータを指定します。 詳しくは格納パラメータを参照してください。 後方互換性のため、テーブルに対するWITH句には新しいテーブルの行にOID(オブジェクト識別子)が含まれないことを示すためにOIDS=FALSEを含めることもできます。OIDS=TRUEはもはやサポートされません。

WITHOUT OIDS #

This is backward-compatible syntax for declaring a table <literal>WITHOUT OIDS</literal>, creating a table <literal>WITH OIDS</literal> is not supported anymore. これはWITHOUT OIDSのテーブルと宣言する後方互換性の構文です。 WITH OIDSのテーブルを作ることはもはやサポートされません。

ON COMMIT #

The behavior of temporary tables at the end of a transaction block can be controlled using <literal>ON COMMIT</literal>. The three options are: ON COMMITを使用して、トランザクションブロックの終了時点での一時テーブルの動作を制御することができます。 以下の3つのオプションがあります。

PRESERVE ROWS #

No special action is taken at the ends of transactions. This is the default behavior. トランザクションの終了時点で、特別な動作は行われません。 これがデフォルトの動作です。

DELETE ROWS #

All rows in the temporary table will be deleted at the end of each transaction block. Essentially, an automatic <link linkend="sql-truncate"><command>TRUNCATE</command></link> is done at each commit. When used on a partitioned table, this is not cascaded to its partitions. 一時テーブル内の全ての行は、各トランザクションブロックの終わりで削除されます。 実質的には、コミットの度に自動的にTRUNCATEが実行されます。 パーティションテーブルに使われた場合、そのパーティションに連鎖適用はされません。

DROP #

The temporary table will be dropped at the end of the current transaction block. When used on a partitioned table, this action drops its partitions and when used on tables with inheritance children, it drops the dependent children. 一時テーブルは現在のトランザクションブロックの終わりで削除されます。 この動作は、パーティションテーブルに使われたときにそのパーティションを削除し、継承の子テーブルを伴うテーブルに使われたときに従属する子テーブルを削除します。

TABLESPACE tablespace_name #

The <replaceable class="parameter">tablespace_name</replaceable> is the name of the tablespace in which the new table is to be created. If not specified, <xref linkend="guc-default-tablespace"/> is consulted, or <xref linkend="guc-temp-tablespaces"/> if the table is temporary. For partitioned tables, since no storage is required for the table itself, the tablespace specified overrides <literal>default_tablespace</literal> as the default tablespace to use for any newly created partitions when no other tablespace is explicitly specified. tablespace_nameは、新しいテーブルが作成されるテーブル空間名です。 指定されていない場合、default_tablespaceが、また一時テーブルの場合はtemp_tablespacesが考慮されます。 パーティションテーブルに対しては、そのテーブル自身ではストレージは必要としないため、他のテーブル空間が明示的に指定されていないときに新しく作成されたパーティションに使用するデフォルトのテーブル空間として、指定されたテーブル空間がdefault_tablespaceを上書きします。

USING INDEX TABLESPACE tablespace_name #

This clause allows selection of the tablespace in which the index associated with a <literal>UNIQUE</literal>, <literal>PRIMARY KEY</literal>, or <literal>EXCLUDE</literal> constraint will be created. If not specified, <xref linkend="guc-default-tablespace"/> is consulted, or <xref linkend="guc-temp-tablespaces"/> if the table is temporary. この句により、UNIQUEPRIMARY KEY、またはEXCLUDE制約に関連したインデックスを作成するテーブル空間を選択することができます。 指定されていない場合、default_tablespaceが、また一時テーブルであればtemp_tablespacesが考慮されます。

<refsect2 id="sql-createtable-storage-parameters" xreflabel="Storage Parameters"> <title>Storage Parameters</title>

格納パラメータ

The <literal>WITH</literal> clause can specify <firstterm>storage parameters</firstterm> for tables, and for indexes associated with a <literal>UNIQUE</literal>, <literal>PRIMARY KEY</literal>, or <literal>EXCLUDE</literal> constraint. Storage parameters for indexes are documented in <xref linkend="sql-createindex"/>. The storage parameters currently available for tables are listed below. For many of these parameters, as shown, there is an additional parameter with the same name prefixed with <literal>toast.</literal>, which controls the behavior of the table's secondary <acronym>TOAST</acronym> table, if any (see <xref linkend="storage-toast"/> for more information about TOAST). If a table parameter value is set and the equivalent <literal>toast.</literal> parameter is not, the TOAST table will use the table's parameter value. Specifying these parameters for partitioned tables is not supported, but you may specify them for individual leaf partitions. WITH句により、テーブルおよびUNIQUEPRIMARY KEY、またはEXCLUDE制約と関連づいたインデックスの格納パラメータを指定することができます。 インデックスの格納パラメータについてはCREATE INDEXで説明します。 現在テーブルで設定可能な格納パラメータの一覧を以下に示します。 これらのパラメータの多くに対して、示した通り、さらにtoastという接頭辞のついた、同一の名前のパラメータがあります。 これはもしあれば、テーブルの補助TOASTテーブルの動作を制御します。 (TOASTに関する詳細については73.2を参照してください。) テーブルのパラメータ値が設定され、それと同等のtoast.パラメータが設定されていない場合、TOASTテーブルはテーブルのパラメータ値を利用します。 これらのパラメータをパーティションテーブルについて指定することはサポートされませんが、個々の末端のパーティションについて指定することはできます。

fillfactor (integer) #

The fillfactor for a table is a percentage between 10 and 100. 100 (complete packing) is the default. When a smaller fillfactor is specified, <command>INSERT</command> operations pack table pages only to the indicated percentage; the remaining space on each page is reserved for updating rows on that page. This gives <command>UPDATE</command> a chance to place the updated copy of a row on the same page as the original, which is more efficient than placing it on a different page, and makes <link linkend="storage-hot">heap-only tuple updates</link> more likely. For a table whose entries are never updated, complete packing is the best choice, but in heavily updated tables smaller fillfactors are appropriate. This parameter cannot be set for TOAST tables. テーブルのフィルファクタ(fillfactor)は10から100までの間の割合(パーセント)です。 100(すべて使用)がデフォルトです。 より小さな値を指定すると、INSERT操作は指定した割合までしかテーブルページを使用しません。 各ページの残りの部分は、そのページ内の行の更新用に予約されます。 これによりUPDATEは、元の行と同じページ上に更新済みの行を格納することができるようになります。 これは別のページに更新済みの行を格納することよりも効率的であり、おそらくより多くヒープ専用タプルの更新を行ないます。 項目の更新がまったくないテーブルでは、すべてを使用することが最善の選択ですが、更新が非常に多いテーブルではより小さめのフィルファクタが適切です。 TOASTテーブルではこのパラメータを設定できません。

toast_tuple_target (integer) #

The toast_tuple_target specifies the minimum tuple length required before we try to compress and/or move long column values into TOAST tables, and is also the target length we try to reduce the length below once toasting begins. This affects columns marked as External (for move), Main (for compression), or Extended (for both) and applies only to new tuples. There is no effect on existing rows. By default this parameter is set to allow at least 4 tuples per block, which with the default block size will be 2040 bytes. Valid values are between 128 bytes and the (block size - header), by default 8160 bytes. Changing this value may not be useful for very short or very long rows. Note that the default setting is often close to optimal, and it is possible that setting this parameter could have negative effects in some cases. This parameter cannot be set for TOAST tables. toast_tuple_targetは、長い列値を圧縮したりTOASTテーブルに移動する前に必要とされる最小タプル長を指定します。また、これはTOAST化を開始したときに長さをそれ未満に減らそうとする目標にもなります。 これはEXTERNAL(移動に対して)、MAIN(圧縮に対して)、または、EXTENDED(両方に対して)と印付けされた列に影響があり、また、新たなタプルにのみ適用されます。 既存の行には影響ありません。 デフォルトでは、このパラメータは1ブロックあたり少なくとも4タプルが可能であるように設定されます。これはデフォルトブロックサイズであれば2040バイトになります。 有効な値は128バイトから、ブロックサイズ - ヘッダ(デフォルトでは8160バイト)の間です。 非常に短いあるいは長い行に対して、この値を変更することはおそらく有用ではありません。 時にはデフォルト設定が最適に近く、本パラメータを設定することで場合によっては悪影響があるかもしれないことに注意してください。

parallel_workers (integer) #

This sets the number of workers that should be used to assist a parallel scan of this table. If not set, the system will determine a value based on the relation size. The actual number of workers chosen by the planner or by utility statements that use parallel scans may be less, for example due to the setting of <xref linkend="guc-max-worker-processes"/>. このテーブルの並列スキャンを支援するために使用されるワーカーの数を設定します。 設定されなければ、リレーションのサイズに基づいてシステムが値を決定します。 プランナやパラレルスキャンを使うユーティリティ文により選ばれるワーカーの数は、例えばmax_worker_processesの設定によって、より少なくなるかもしれません。

autovacuum_enabled, toast.autovacuum_enabled (boolean) #

Enables or disables the autovacuum daemon for a particular table. If true, the autovacuum daemon will perform automatic <command>VACUUM</command> and/or <command>ANALYZE</command> operations on this table following the rules discussed in <xref linkend="autovacuum"/>. If false, this table will not be autovacuumed, except to prevent transaction ID wraparound. See <xref linkend="vacuum-for-wraparound"/> for more about wraparound prevention. Note that the autovacuum daemon does not run at all (except to prevent transaction ID wraparound) if the <xref linkend="guc-autovacuum"/> parameter is false; setting individual tables' storage parameters does not override that. Therefore there is seldom much point in explicitly setting this storage parameter to <literal>true</literal>, only to <literal>false</literal>. 特定のテーブルに対する自動バキュームデーモンを有効または無効にします。 trueの場合、自動バキュームデーモンは、25.1.6に記述されたルールに従って、このテーブルに対して自動的にVACUUMあるいはANALYZEまたはその両方の操作を行います。 falseの場合、トランザクションIDの周回問題を回避するためを除き自動バキュームは行われません。 周回問題の回避については25.1.5を参照してください。 autovacuumパラメータがfalseの場合、(トランザクションIDの周回問題を回避する場合を除き)自動バキュームデーモンはまったく実行されないことに注意して下さい。 個々のテーブルの格納パラメータを設定しても、それは優先されません。 従って、この格納パラメータを明示的にtrueに設定することにはほとんど意味はなく、falseに設定することのみが意味を持ちます。

vacuum_index_cleanup, toast.vacuum_index_cleanup (enum) #

Forces or disables index cleanup when <command>VACUUM</command> is run on this table. The default value is <literal>AUTO</literal>. With <literal>OFF</literal>, index cleanup is disabled, with <literal>ON</literal> it is enabled, and with <literal>AUTO</literal> a decision is made dynamically, each time <command>VACUUM</command> runs. The dynamic behavior allows <command>VACUUM</command> to avoid needlessly scanning indexes to remove very few dead tuples. Forcibly disabling all index cleanup can speed up <command>VACUUM</command> very significantly, but may also lead to severely bloated indexes if table modifications are frequent. The <literal>INDEX_CLEANUP</literal> parameter of <link linkend="sql-vacuum"><command>VACUUM</command></link>, if specified, overrides the value of this option. このテーブルにVACUUMが実行されたときのインデックスのクリーンアップを強制または無効にします。 デフォルト値はAUTOです。 OFFでインデックスのクリーンアップは無効になり、ONで有効に、AUTOでその時々のVACUUM実行時に決定が動的に行なわれるようになります。 動的な動作により、ほとんどない無効タプル削除するために必要もないのにインデックスをスキャンしてしまうことをVACUUMが避けられるようになります。 インデックスのクリーンアップを強制的にすべて無効にすることで、VACUUMを大幅に高速化できますが、テーブルの変更が頻繁である場合には深刻なインデックスの肥大化も生じさせるかもしれません。 VACUUMINDEX_CLEANUPパラメータは、指定されていたなら本オプションを上書きします。

vacuum_truncate, toast.vacuum_truncate (boolean) #

Enables or disables vacuum to try to truncate off any empty pages at the end of this table. The default value is <literal>true</literal>. If <literal>true</literal>, <command>VACUUM</command> and autovacuum do the truncation and the disk space for the truncated pages is returned to the operating system. Note that the truncation requires <literal>ACCESS EXCLUSIVE</literal> lock on the table. The <literal>TRUNCATE</literal> parameter of <link linkend="sql-vacuum"><command>VACUUM</command></link>, if specified, overrides the value of this option. バキュームがテーブル末尾の空ページの切り捨てを試みることを、有効または無効にします。 デフォルト値はtrueです。 trueの場合、VACUUMと自動バキュームは切り捨てを行い切り捨てられたページのディスク領域はオペレーティングシステムに返されます。 切り捨てにはテーブルにACCESS EXCLUSIVEロックが必要であることに注意してください。 VACUUMTRUNCATEパラメータは、指定されていたなら本オプションを上書きします。

autovacuum_vacuum_threshold, toast.autovacuum_vacuum_threshold (integer) #

Per-table value for <xref linkend="guc-autovacuum-vacuum-threshold"/> parameter. autovacuum_vacuum_thresholdパラメータについて、テーブル毎に設定する値です。

autovacuum_vacuum_scale_factor, toast.autovacuum_vacuum_scale_factor (floating point) #

Per-table value for <xref linkend="guc-autovacuum-vacuum-scale-factor"/> parameter. autovacuum_vacuum_scale_factorパラメータについて、テーブル毎に設定する値です。

autovacuum_vacuum_insert_threshold, toast.autovacuum_vacuum_insert_threshold (integer) #

Per-table value for <xref linkend="guc-autovacuum-vacuum-insert-threshold"/> parameter. The special value of -1 may be used to disable insert vacuums on the table. autovacuum_vacuum_insert_thresholdパラメータについて、テーブル毎に設定する値です。 特別な値である-1は、テーブルでのインサートバキュームを無効にするのに使われます。

autovacuum_vacuum_insert_scale_factor, toast.autovacuum_vacuum_insert_scale_factor (floating point) #

Per-table value for <xref linkend="guc-autovacuum-vacuum-insert-scale-factor"/> parameter. autovacuum_vacuum_insert_scale_factorパラメータについて、テーブル毎に設定する値です。

autovacuum_analyze_threshold (integer) #

Per-table value for <xref linkend="guc-autovacuum-analyze-threshold"/> parameter. autovacuum_analyze_thresholdパラメータについて、テーブル毎に設定する値です。

autovacuum_analyze_scale_factor (floating point) #

Per-table value for <xref linkend="guc-autovacuum-analyze-scale-factor"/> parameter. autovacuum_analyze_scale_factorパラメータについて、テーブル毎に設定する値です。

autovacuum_vacuum_cost_delay, toast.autovacuum_vacuum_cost_delay (floating point) #

Per-table value for <xref linkend="guc-autovacuum-vacuum-cost-delay"/> parameter. autovacuum_vacuum_cost_delayパラメータについて、テーブル毎に設定する値です。

autovacuum_vacuum_cost_limit, toast.autovacuum_vacuum_cost_limit (integer) #

Per-table value for <xref linkend="guc-autovacuum-vacuum-cost-limit"/> parameter. autovacuum_vacuum_cost_limitパラメータについて、テーブル毎に設定する値です。

autovacuum_freeze_min_age, toast.autovacuum_freeze_min_age (integer) #

Per-table value for <xref linkend="guc-vacuum-freeze-min-age"/> parameter. Note that autovacuum will ignore per-table <literal>autovacuum_freeze_min_age</literal> parameters that are larger than half the system-wide <xref linkend="guc-autovacuum-freeze-max-age"/> setting. vacuum_freeze_min_ageパラメータについて、テーブル毎に設定する値です。 テーブル単位のautovacuum_freeze_min_ageパラメータをシステム全体のautovacuum_freeze_max_age設定の1/2より大きく設定しても、自動バキュームが無視することに注意してください。

autovacuum_freeze_max_age, toast.autovacuum_freeze_max_age (integer) #

Per-table value for <xref linkend="guc-autovacuum-freeze-max-age"/> parameter. Note that autovacuum will ignore per-table <literal>autovacuum_freeze_max_age</literal> parameters that are larger than the system-wide setting (it can only be set smaller). autovacuum_freeze_max_ageパラメータについて、テーブル毎に設定する値です。 テーブル単位のautovacuum_freeze_max_ageパラメータをシステム全体に対する設定より大きく設定しても、自動バキュームが無視することに注意してください(より小さな値しか設定できません)。

autovacuum_freeze_table_age, toast.autovacuum_freeze_table_age (integer) #

Per-table value for <xref linkend="guc-vacuum-freeze-table-age"/> parameter. vacuum_freeze_table_ageパラメータについて、テーブル毎に設定する値です。

autovacuum_multixact_freeze_min_age, toast.autovacuum_multixact_freeze_min_age (integer) #

Per-table value for <xref linkend="guc-vacuum-multixact-freeze-min-age"/> parameter. Note that autovacuum will ignore per-table <literal>autovacuum_multixact_freeze_min_age</literal> parameters that are larger than half the system-wide <xref linkend="guc-autovacuum-multixact-freeze-max-age"/> setting. vacuum_multixact_freeze_min_ageパラメータについて、テーブル毎に設定する値です。 テーブル単位のautovacuum_multixact_freeze_min_ageパラメータをシステム全体のautovacuum_multixact_freeze_max_ageの半分より大きく設定しても、自動バキュームが無視することに注意してください。

autovacuum_multixact_freeze_max_age, toast.autovacuum_multixact_freeze_max_age (integer) #

Per-table value for <xref linkend="guc-autovacuum-multixact-freeze-max-age"/> parameter. Note that autovacuum will ignore per-table <literal>autovacuum_multixact_freeze_max_age</literal> parameters that are larger than the system-wide setting (it can only be set smaller). autovacuum_multixact_freeze_max_ageパラメータについて、テーブル毎に設定する値です。 テーブル単位のautovacuum_multixact_freeze_max_ageをシステム全体に対する設定より大きくしても、自動バキュームが無視することに注意してください(より小さな値しか設定できません)。

autovacuum_multixact_freeze_table_age, toast.autovacuum_multixact_freeze_table_age (integer) #

Per-table value for <xref linkend="guc-vacuum-multixact-freeze-table-age"/> parameter. vacuum_multixact_freeze_table_ageパラメータについて、テーブル毎に設定する値です。

log_autovacuum_min_duration, toast.log_autovacuum_min_duration (integer) #

Per-table value for <xref linkend="guc-log-autovacuum-min-duration"/> parameter. log_autovacuum_min_durationパラメータについて、テーブル毎に設定する値です。

user_catalog_table (boolean) #

Declare the table as an additional catalog table for purposes of logical replication. See <xref linkend="logicaldecoding-capabilities"/> for details. This parameter cannot be set for TOAST tables. テーブルを論理レプリケーションのための追加のカタログテーブルとして宣言します。 詳しくは49.6.2を参照してください。 このパラメータはTOASTテーブルには設定できません。

注釈

<title>Notes</title>

<productname>PostgreSQL</productname> automatically creates an index for each unique constraint and primary key constraint to enforce uniqueness. Thus, it is not necessary to create an index explicitly for primary key columns. (See <xref linkend="sql-createindex"/> for more information.) PostgreSQLは自動的に各一意性制約と主キー制約に対してインデックスを作成し、その一意性を確実なものにします。 したがって、主キーの列に明示的にインデックスを作成することは必要ありません (詳細についてはCREATE INDEXを参照してください)。

Unique constraints and primary keys are not inherited in the current implementation. This makes the combination of inheritance and unique constraints rather dysfunctional. 現在の実装では、一意性制約と主キーは継承されません。 これは、継承と一意性制約を組み合わせると障害が発生するからです。

A table cannot have more than 1600 columns. (In practice, the effective limit is usually lower because of tuple-length constraints.) テーブルは1600列以上の列を持つことはできません (タプル長の制限により実際の制限はもっと小さくなります)。

<title>Examples</title>

Create table <structname>films</structname> and table <structname>distributors</structname>: filmsテーブルとdistributorsテーブルを作成します。

CREATE TABLE films (
    code        char(5) CONSTRAINT firstkey PRIMARY KEY,
    title       varchar(40) NOT NULL,
    did         integer NOT NULL,
    date_prod   date,
    kind        varchar(10),
    len         interval hour to minute
);

CREATE TABLE distributors (
     did    integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
     name   varchar(40) NOT NULL CHECK (name <> '')
);

Create a table with a 2-dimensional array: 2次元配列を持つテーブルを作成します。

CREATE TABLE array_int (
    vector  int[][]
);

Define a unique table constraint for the table <literal>films</literal>. Unique table constraints can be defined on one or more columns of the table: filmsテーブルに 一意性テーブル制約を定義します。 一意性テーブル制約はテーブルの1つ以上の列に定義することができます。

CREATE TABLE films (
    code        char(5),
    title       varchar(40),
    did         integer,
    date_prod   date,
    kind        varchar(10),
    len         interval hour to minute,
    CONSTRAINT production UNIQUE(date_prod)
);

Define a check column constraint: 検査列制約を定義します。

CREATE TABLE distributors (
    did     integer CHECK (did > 100),
    name    varchar(40)
);

Define a check table constraint: 検査テーブル制約を定義します。

CREATE TABLE distributors (
    did     integer,
    name    varchar(40),
    CONSTRAINT con1 CHECK (did > 100 AND name <> '')
);

Define a primary key table constraint for the table <structname>films</structname>: filmsテーブルに主キーテーブル制約を定義します。

CREATE TABLE films (
    code        char(5),
    title       varchar(40),
    did         integer,
    date_prod   date,
    kind        varchar(10),
    len         interval hour to minute,
    CONSTRAINT code_title PRIMARY KEY(code,title)
);

Define a primary key constraint for table <structname>distributors</structname>. The following two examples are equivalent, the first using the table constraint syntax, the second the column constraint syntax: distributorsテーブルに主キー制約を定義します。 以下の2つの例は同等で、前者はテーブル制約構文を使用し、後者は列制約構文を使用します。

CREATE TABLE distributors (
    did     integer,
    name    varchar(40),
    PRIMARY KEY(did)
);

CREATE TABLE distributors (
    did     integer PRIMARY KEY,
    name    varchar(40)
);

Assign a literal constant default value for the column <literal>name</literal>, arrange for the default value of column <literal>did</literal> to be generated by selecting the next value of a sequence object, and make the default value of <literal>modtime</literal> be the time at which the row is inserted: 以下では、name列のデフォルト値にリテラル定数を割り当てています。また、did列のデフォルト値として、シーケンスオブジェクトの次の値が生成されるように調整しています。 modtimeのデフォルト値は、その行が挿入された時刻となります。

CREATE TABLE distributors (
    name      varchar(40) DEFAULT 'Luso Films',
    did       integer DEFAULT nextval('distributors_serial'),
    modtime   timestamp DEFAULT current_timestamp
);

Define two <literal>NOT NULL</literal> column constraints on the table <classname>distributors</classname>, one of which is explicitly given a name: 2つのNOT NULL列制約をdistributorsテーブルに定義します。 そのうち1つには明示的な名前を付けています。

CREATE TABLE distributors (
    did     integer CONSTRAINT no_null NOT NULL,
    name    varchar(40) NOT NULL
);

Define a unique constraint for the <literal>name</literal> column: name列に対し、一意性制約を定義します。

CREATE TABLE distributors (
    did     integer,
    name    varchar(40) UNIQUE
);

The same, specified as a table constraint: 上と同じですが、テーブル制約として指定します。

CREATE TABLE distributors (
    did     integer,
    name    varchar(40),
    UNIQUE(name)
);

Create the same table, specifying 70% fill factor for both the table and its unique index: テーブルとその一意性インデックスの両方に70%のフィルファクタを指定して、同じテーブルを作成します。

CREATE TABLE distributors (
    did     integer,
    name    varchar(40),
    UNIQUE(name) WITH (fillfactor=70)
)
WITH (fillfactor=70);

Create table <structname>circles</structname> with an exclusion constraint that prevents any two circles from overlapping: 2つの円の重複を許さない排他制約を持つcirclesテーブルを作成します。

CREATE TABLE circles (
    c circle,
    EXCLUDE USING gist (c WITH &&)
);

Create table <structname>cinemas</structname> in tablespace <structname>diskvol1</structname>: diskvol1テーブル空間にcinemasテーブルを作成します。

CREATE TABLE cinemas (
        id serial,
        name text,
        location text
) TABLESPACE diskvol1;

Create a composite type and a typed table: 複合型と型付きテーブルを作成します。

CREATE TYPE employee_type AS (name text, salary numeric);

CREATE TABLE employees OF employee_type (
    PRIMARY KEY (name),
    salary WITH OPTIONS DEFAULT 1000
);

Create a range partitioned table: 範囲パーティションテーブルを作成します。

CREATE TABLE measurement (
    logdate         date not null,
    peaktemp        int,
    unitsales       int
) PARTITION BY RANGE (logdate);

Create a range partitioned table with multiple columns in the partition key: パーティションキーに複数の列がある範囲パーティションテーブルを作成します。

CREATE TABLE measurement_year_month (
    logdate         date not null,
    peaktemp        int,
    unitsales       int
) PARTITION BY RANGE (EXTRACT(YEAR FROM logdate), EXTRACT(MONTH FROM logdate));

Create a list partitioned table: リストパーティションテーブルを作成します。

CREATE TABLE cities (
    city_id      bigserial not null,
    name         text not null,
    population   bigint
) PARTITION BY LIST (left(lower(name), 1));

Create a hash partitioned table: ハッシュパーティションテーブルを作成します。

CREATE TABLE orders (
    order_id     bigint not null,
    cust_id      bigint not null,
    status       text
) PARTITION BY HASH (order_id);

Create partition of a range partitioned table: 範囲パーティションテーブルのパーティションを作成します。

CREATE TABLE measurement_y2016m07
    PARTITION OF measurement (
    unitsales DEFAULT 0
) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01');

Create a few partitions of a range partitioned table with multiple columns in the partition key: パーティションキーに複数の列がある範囲パーティションテーブルに、パーティションをいくつか作成します。

CREATE TABLE measurement_ym_older
    PARTITION OF measurement_year_month
    FOR VALUES FROM (MINVALUE, MINVALUE) TO (2016, 11);

CREATE TABLE measurement_ym_y2016m11
    PARTITION OF measurement_year_month
    FOR VALUES FROM (2016, 11) TO (2016, 12);

CREATE TABLE measurement_ym_y2016m12
    PARTITION OF measurement_year_month
    FOR VALUES FROM (2016, 12) TO (2017, 01);

CREATE TABLE measurement_ym_y2017m01
    PARTITION OF measurement_year_month
    FOR VALUES FROM (2017, 01) TO (2017, 02);

Create partition of a list partitioned table: リストパーティションテーブルのパーティションを作成します。

CREATE TABLE cities_ab
    PARTITION OF cities (
    CONSTRAINT city_id_nonzero CHECK (city_id != 0)
) FOR VALUES IN ('a', 'b');

Create partition of a list partitioned table that is itself further partitioned and then add a partition to it: リストパーティションテーブルにパーティションを作成しますが、それ自体がさらにパーティションになり、それにパーティションを追加します。

CREATE TABLE cities_ab
    PARTITION OF cities (
    CONSTRAINT city_id_nonzero CHECK (city_id != 0)
) FOR VALUES IN ('a', 'b') PARTITION BY RANGE (population);

CREATE TABLE cities_ab_10000_to_100000
    PARTITION OF cities_ab FOR VALUES FROM (10000) TO (100000);

Create partitions of a hash partitioned table: ハッシュパーティションテーブルのパーティションを作成します。

CREATE TABLE orders_p1 PARTITION OF orders
    FOR VALUES WITH (MODULUS 4, REMAINDER 0);
CREATE TABLE orders_p2 PARTITION OF orders
    FOR VALUES WITH (MODULUS 4, REMAINDER 1);
CREATE TABLE orders_p3 PARTITION OF orders
    FOR VALUES WITH (MODULUS 4, REMAINDER 2);
CREATE TABLE orders_p4 PARTITION OF orders
    FOR VALUES WITH (MODULUS 4, REMAINDER 3);

Create a default partition: デフォルトのパーティションを作成します。

CREATE TABLE cities_partdef
    PARTITION OF cities DEFAULT;
<refsect1 id="sql-createtable-compatibility" xreflabel="Compatibility"> <title>Compatibility</title>

互換性

The <command>CREATE TABLE</command> command conforms to the <acronym>SQL</acronym> standard, with exceptions listed below. CREATE TABLEは、以下に挙げるものを除いて、標準SQLに従います。

一時テーブル

<title>Temporary Tables</title>

Although the syntax of <literal>CREATE TEMPORARY TABLE</literal> resembles that of the SQL standard, the effect is not the same. In the standard, temporary tables are defined just once and automatically exist (starting with empty contents) in every session that needs them. <productname>PostgreSQL</productname> instead requires each session to issue its own <literal>CREATE TEMPORARY TABLE</literal> command for each temporary table to be used. This allows different sessions to use the same temporary table name for different purposes, whereas the standard's approach constrains all instances of a given temporary table name to have the same table structure. CREATE TEMPORARY TABLEは標準SQLに類似していますが、その効果は同じではありません。 標準では、一時テーブルは一度だけ定義され、それを必要とするセッションごとに自動的に(空の内容で始まる形で)出現します。 PostgreSQLでは、これと異なり、各セッションで独自に、使用する一時テーブル用のCREATE TEMPORARY TABLEコマンドを発行しなければなりません。 これにより、異なるセッションで同じ名前の一時テーブルを異なる目的で使用することができます。 一方、標準の方法では、ある一時テーブル名を持つインスタンスが、全て同一のテーブル構造を持つという制限があります。

The standard's definition of the behavior of temporary tables is widely ignored. <productname>PostgreSQL</productname>'s behavior on this point is similar to that of several other SQL databases. 標準における一時テーブルの動作定義の多くは無視されています。 この点でのPostgreSQLの動作は、他の多くのSQLデータベースと似ています。

The SQL standard also distinguishes between global and local temporary tables, where a local temporary table has a separate set of contents for each SQL module within each session, though its definition is still shared across sessions. Since <productname>PostgreSQL</productname> does not support SQL modules, this distinction is not relevant in <productname>PostgreSQL</productname>. また標準SQLではグローバル一時テーブルとローカル一時テーブルを区別しています。 ローカル一時テーブルは各セッション内のSQLモジュールそれぞれ用に内容の集合を分離しますが、その定義はセッション全体で共有されます。 PostgreSQLはSQLモジュールをサポートしませんので、PostgreSQLではこの区別は適切ではありません。

For compatibility's sake, <productname>PostgreSQL</productname> will accept the <literal>GLOBAL</literal> and <literal>LOCAL</literal> keywords in a temporary table declaration, but they currently have no effect. Use of these keywords is discouraged, since future versions of <productname>PostgreSQL</productname> might adopt a more standard-compliant interpretation of their meaning. 互換性を保持するため、PostgreSQLは一時テーブルの宣言においてGLOBALLOCALキーワードを受け付けますが、これらには現在、何の効果もありません。 PostgreSQLの今後のバージョンでは、これらの意味についてより標準に近い実装を取り入れる可能性がありますので、これらのキーワードの使用は勧めません。

The <literal>ON COMMIT</literal> clause for temporary tables also resembles the SQL standard, but has some differences. If the <literal>ON COMMIT</literal> clause is omitted, SQL specifies that the default behavior is <literal>ON COMMIT DELETE ROWS</literal>. However, the default behavior in <productname>PostgreSQL</productname> is <literal>ON COMMIT PRESERVE ROWS</literal>. The <literal>ON COMMIT DROP</literal> option does not exist in SQL. 一時テーブル用のON COMMIT句もまた、標準SQLに類似していますが、いくつか違いがあります。 ON COMMIT句が省略された場合、SQLでは、デフォルトの動作はON COMMIT DELETE ROWSであると規定しています。 しかし、PostgreSQLでのデフォルトの動作はON COMMIT PRESERVE ROWSです。 また、ON COMMIT DROPはSQLにはありません。

非遅延一意性制約

<title>Non-Deferred Uniqueness Constraints</title>

When a <literal>UNIQUE</literal> or <literal>PRIMARY KEY</literal> constraint is not deferrable, <productname>PostgreSQL</productname> checks for uniqueness immediately whenever a row is inserted or modified. The SQL standard says that uniqueness should be enforced only at the end of the statement; this makes a difference when, for example, a single command updates multiple key values. To obtain standard-compliant behavior, declare the constraint as <literal>DEFERRABLE</literal> but not deferred (i.e., <literal>INITIALLY IMMEDIATE</literal>). Be aware that this can be significantly slower than immediate uniqueness checking. UNIQUEまたはPRIMARY KEY制約が非遅延の場合、PostgreSQLは行が挿入または変更されると即座に一意性を検査します。 標準SQLでは一意性は文が完了した時にのみ強制されなければならないと記述しています。 これにより、たとえば、1つのコマンドが複数のキー値を更新する時に違いが現れます。 標準互換の動作をさせるためには、非遅延(つまりINITIALLY IMMEDIATE)ではなくDEFERRABLEとして制約を宣言してください。 これが即座に行われる一意性検査よりかなり低速になる可能性があることに注意してください。

列検査制約

<title>Column Check Constraints</title>

The SQL standard says that <literal>CHECK</literal> column constraints can only refer to the column they apply to; only <literal>CHECK</literal> table constraints can refer to multiple columns. <productname>PostgreSQL</productname> does not enforce this restriction; it treats column and table check constraints alike. 標準SQLでは、CHECK列制約はそれを適用する列のみを参照でき、複数の列を参照できるのはCHECKテーブル制約のみであるとされています。 PostgreSQLにはこの制限はありません。 列検査制約とテーブル検査制約を同様のものとして扱っています。

EXCLUDE制約

<title><literal>EXCLUDE</literal> Constraint</title>

The <literal>EXCLUDE</literal> constraint type is a <productname>PostgreSQL</productname> extension. EXCLUDEという種類の制約はPostgreSQLの拡張です。

外部キー制約アクション

<title>Foreign-Key Constraint Actions</title>

The ability to specify column lists in the foreign-key actions <literal>SET DEFAULT</literal> and <literal>SET NULL</literal> is a <productname>PostgreSQL</productname> extension. 外部キーアクションSET DEFAULTSET NULLで列のリストを指定する機能はPostgreSQLの拡張です。

NULL 制約

<title><literal>NULL</literal> <quote>Constraint</quote></title>

The <literal>NULL</literal> <quote>constraint</quote> (actually a non-constraint) is a <productname>PostgreSQL</productname> extension to the SQL standard that is included for compatibility with some other database systems (and for symmetry with the <literal>NOT NULL</literal> constraint). Since it is the default for any column, its presence is simply noise. NULL制約(実際には非制約)は、標準SQLに対するPostgreSQLの拡張で、他のいくつかのデータベースシステムとの互換性(および NOT NULL制約との対称性)のために含まれています。 どんな列に対してもデフォルトとなるため、これには意味はありません。

制約の命名

<title>Constraint Naming</title>

The SQL standard says that table and domain constraints must have names that are unique across the schema containing the table or domain. <productname>PostgreSQL</productname> is laxer: it only requires constraint names to be unique across the constraints attached to a particular table or domain. However, this extra freedom does not exist for index-based constraints (<literal>UNIQUE</literal>, <literal>PRIMARY KEY</literal>, and <literal>EXCLUDE</literal> constraints), because the associated index is named the same as the constraint, and index names must be unique across all relations within the same schema. SQL標準ではテーブルとドメインの制約はテーブルやドメインを含むスキーマ中で一意な名前を持たなければなりません。 PostgreSQLはより緩やかで、制約名は特定のテーブルやドメインに付加された制約の中で一意であることだけが求められます。 しかしながら、この追加的な自由はインデックスに基づく制約(UNIQUEPRIMARY KEY、およびEXCLUDE制約)にはありません。なぜなら、関連付けられたインデックスは制約と同じに命名されて、インデックス名は同スキーマ内の全てのリレーションの中で一意でなければならないからです。

Currently, <productname>PostgreSQL</productname> does not record names for <literal>NOT NULL</literal> constraints at all, so they are not subject to the uniqueness restriction. This might change in a future release. 今のところ、PostgreSQLNOT NULL制約の名前を全く記録しませんので、これらは一意性の制限の対象ではありません。 これは将来のリリースで変更されるかもしれません。

継承

<title>Inheritance</title>

Multiple inheritance via the <literal>INHERITS</literal> clause is a <productname>PostgreSQL</productname> language extension. SQL:1999 and later define single inheritance using a different syntax and different semantics. SQL:1999-style inheritance is not yet supported by <productname>PostgreSQL</productname>. INHERITS句による複数継承は、PostgreSQLの言語拡張です。 SQL:1999以降では、異なる構文と意味体系による単一継承を定義しています。 今のところ、SQL:1999方式の継承はPostgreSQLではサポートされていません。

列を持たないテーブル

<title>Zero-Column Tables</title>

<productname>PostgreSQL</productname> allows a table of no columns to be created (for example, <literal>CREATE TABLE foo();</literal>). This is an extension from the SQL standard, which does not allow zero-column tables. Zero-column tables are not in themselves very useful, but disallowing them creates odd special cases for <command>ALTER TABLE DROP COLUMN</command>, so it seems cleaner to ignore this spec restriction. PostgreSQLでは、列を持たないテーブルを作成することができます (例えば、CREATE TABLE foo();)。 これは標準SQLからの拡張です。 標準SQLでは列を持たないテーブルは許されません。 列を持たないテーブルそれ自体は役に立ちませんが、これを無効とすると、ALTER TABLE DROP COLUMNに対して奇妙な特例を生成することになります。 したがって、この仕様上の制限を無視する方が簡潔であると考えます。

複数のIDENTITY列

<title>Multiple Identity Columns</title>

<productname>PostgreSQL</productname> allows a table to have more than one identity column. The standard specifies that a table can have at most one identity column. This is relaxed mainly to give more flexibility for doing schema changes or migrations. Note that the <command>INSERT</command> command supports only one override clause that applies to the entire statement, so having multiple identity columns with different behaviors is not well supported. PostgreSQLではテーブルに2つ以上のIDENTITY列を持つことを許しています。 標準SQLでは、1つのテーブルは最大で1つのIDENTITY列を持つことができると規定しています。 主にスキーマの変更や移行でより柔軟性を持たせるために、この制約を緩和しています。 INSERTコマンドはOVERRIDING句を1つだけしかサポートせず、これが文全体に適用されるため、複数のIDENTITY列があり、これらの動作が異なる場合は正しくサポートされないことに注意してください。

生成列

<title>Generated Columns</title>

The option <literal>STORED</literal> is not standard but is also used by other SQL implementations. The SQL standard does not specify the storage of generated columns. オプションSTOREDは標準ではありませんが他のSQL実装でも使われています。SQL標準は生成列の格納を規定していません。

LIKE

<title><literal>LIKE</literal> Clause</title>

While a <literal>LIKE</literal> clause exists in the SQL standard, many of the options that <productname>PostgreSQL</productname> accepts for it are not in the standard, and some of the standard's options are not implemented by <productname>PostgreSQL</productname>. LIKE句は標準SQLにありますが、PostgreSQLで利用可能な多くのオプションは標準にはなく、また標準のオプションの一部はPostgreSQLでは実装されていません。

WITH

<title><literal>WITH</literal> Clause</title>

The <literal>WITH</literal> clause is a <productname>PostgreSQL</productname> extension; storage parameters are not in the standard. WITH句はPostgreSQLの拡張です。 格納パラメータは標準にはありません。

テーブル空間

<title>Tablespaces</title>

The <productname>PostgreSQL</productname> concept of tablespaces is not part of the standard. Hence, the clauses <literal>TABLESPACE</literal> and <literal>USING INDEX TABLESPACE</literal> are extensions. PostgreSQLのテーブル空間の概念は標準にはありません。 したがって、TABLESPACEUSING INDEX TABLESPACEは、PostgreSQLにおける拡張です。

型付きテーブル

<title>Typed Tables</title>

Typed tables implement a subset of the SQL standard. According to the standard, a typed table has columns corresponding to the underlying composite type as well as one other column that is the <quote>self-referencing column</quote>. <productname>PostgreSQL</productname> does not support self-referencing columns explicitly. 型付きテーブルは標準SQLのサブセットを実装します。 標準に従うと、型付きテーブルは背後の複合型に対応した列の他に自己参照列という列も持ちます。 PostgreSQLは自己参照列を明示的にサポートしません。

PARTITION BY

<title><literal>PARTITION BY</literal> Clause</title>

The <literal>PARTITION BY</literal> clause is a <productname>PostgreSQL</productname> extension. PARTITION BYPostgreSQLの拡張です。

PARTITION OF

<title><literal>PARTITION OF</literal> Clause</title>

The <literal>PARTITION OF</literal> clause is a <productname>PostgreSQL</productname> extension. PARTITION OF句はPostgreSQLの拡張です。

関連項目

<title>See Also</title> ALTER TABLE, DROP TABLE, CREATE TABLE AS, CREATE TABLESPACE, CREATE TYPE