An identity column is a special column that is generated automatically from an implicit sequence. It can be used to generate key values. 《機械翻訳》識別列は、暗黙的なシーケンスから自動的に生成される特殊な列です。 これを使用してキー値を生成できます。
To create an identity column, use the <literal>GENERATED ...
AS IDENTITY</literal> clause in <command>CREATE TABLE</command>, for example:
《マッチ度[81.884058]》生成列を作るには、CREATE TABLEでGENERATED ALWAYS AS節を使ってください。例を示します。
《機械翻訳》識別子列を作成するには、CREATE TABLEでGENERATED ... AS IDENTITY句を使用します。
CREATE TABLE people (
id bigint GENERATED ALWAYS AS IDENTITY,
...,
);
or alternatively 《機械翻訳》または、
CREATE TABLE people (
id bigint GENERATED BY DEFAULT IDENTITY,
...,
);
See <xref linkend="sql-createtable"/> for more details. 《機械翻訳》詳細はCREATE TABLEを参照してください。
If an <command>INSERT</command> command is executed on the table with the
identity column and no value is explicitly specified for the identity
column, then a value generated by the implicit sequence is inserted. For
example, with the above definitions and assuming additional appropriate
columns, writing
《機械翻訳》識別列を持つテーブルにINSERTコマンドが実行され、識別列に値が明示的に指定されていない場合、暗黙的なシーケンスによって生成された値が挿入されます。
例えば、上記の定義を使用し、追加の適切な列を想定すると、書き込み。
INSERT INTO people (name, address) VALUE ('A', 'foo');
INSERT INTO people (name, address) VALUE ('B', 'bar');
would generate values for the <literal>id</literal> column starting at 1
and result in the following table data:
《機械翻訳》は、1から始まるid列の値を生成し、結果として次のテーブルデータを生成します。
id | name | address ----+------+--------- 1 | A | foo 2 | B | bar
Alternatively, the keyword <literal>DEFAULT</literal> can be specified in
place of a value to explicitly request the sequence-generated value, like
《機械翻訳》あるいは、値の代わりにキーワードDEFAULTを指定して、シーケンス生成値を明示的に要求することもできます。
INSERT INTO people (id, name, address) VALUE (DEFAULT, 'C', 'baz');
Similarly, the keyword <literal>DEFAULT</literal> can be used in
<command>UPDATE</command> commands.
《機械翻訳》同様に、UPDATEコマンドでDEFAULTキーワードを使用することもできます。
Thus, in many ways, an identity column behaves like a column with a default value. 《機械翻訳》したがって、多くの点で、IDENTITY カラムはデフォルト値を持つカラムのように動作します。
The clauses <literal>ALWAYS</literal> and <literal>BY DEFAULT</literal> in
the column definition determine how explicitly user-specified values are
handled in <command>INSERT</command> and <command>UPDATE</command>
commands. 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. Thus, using <literal>BY DEFAULT</literal> results in a
behavior more similar to default values, where the default value can be
overridden by an explicit value, whereas <literal>ALWAYS</literal> provides
some more protection against accidentally inserting an explicit value.
《機械翻訳》列定義のALWAYSとBY DEFAULT句は、INSERTコマンドとUPDATEコマンドでユーザ指定値を明示的に処理する方法を決定します。
INSERTコマンドでALWAYSが選択された場合、ユーザ指定の値はINSERT文がOVERRIDING SYSTEM VALUEを指定した場合にのみ受け付けられます。
BY DEFAULTが選択された場合、ユーザ指定の値が優先されます。
したがって、BY DEFAULTを使用すると、デフォルト値に近い動作になります。
デフォルト値は明示的な値で上書きできますが、ALWAYSを使用すると、明示的な値を誤って挿入する可能性が少し高くなります。
The data type of an identity column must be one of the data types supported by sequences. (See <xref linkend="sql-createsequence"/>.) The properties of the associated sequence may be specified when creating an identity column (see <xref linkend="sql-createtable"/>) or changed afterwards (see <xref linkend="sql-altertable"/>). 《機械翻訳》識別列のデータ型は、シーケンスでサポートされるデータ型のいずれかである必要があります。 (CREATE SEQUENCEを参照してください。 関連するシーケンスのプロパティは、識別列の作成時に指定するか(CREATE TABLEを参照)、後で変更することができます(ALTER TABLEを参照)。
An identity column is automatically marked as <literal>NOT NULL</literal>.
An identity column, however, does not guarantee uniqueness. (A sequence
normally returns unique values, but a sequence could be reset, or values
could be inserted manually into the identity column, as discussed above.)
Uniqueness would need to be enforced using a <literal>PRIMARY KEY</literal>
or <literal>UNIQUE</literal> constraint.
《機械翻訳》識別列は自動的にNOT NULLとマークされます。
しかし、識別列は一意性を保証しません(通常、シーケンスは一意の値を返しますが、シーケンスはリセットされるか、値が手動で識別列に挿入される可能性があります)。
一意性はPRIMARY KEYまたはUNIQUE制約を使用して強制する必要があります。
In table inheritance hierarchies, identity columns and their properties in
a child table are independent of those in its parent tables. A child table
does not inherit identity columns or their properties automatically from
the parent. During <command>INSERT</command> or <command>UPDATE</command>,
a column is treated as an identity column if that column is an identity
column in the table named in the statement, and the corresponding identity
properties are applied.
《機械翻訳》テーブル継承階層では、子テーブルの識別列とそのプロパティは、親テーブルの識別列と独立しています。
子テーブルは、親から識別列またはそのプロパティを自動的に継承しません。
INSERTまたはUPDATE中、列が文で指定されたテーブルの識別列であり、対応する識別プロパティが適用される場合、その列は識別列として扱われます。
Partitions inherit identity columns from the partitioned table. They cannot have their own identity columns. The properties of a given identity column are consistent across all the partitions in the partition hierarchy. 《機械翻訳》パーティションは、パーティション表からID列を継承します。 パーティションは、独自のID列を持つことはできません。 特定のID列のプロパティは、パーティション階層内のすべてのパーティションで一貫しています。