@@ -81,7 +81,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
81
81
UNIQUE [ NULLS [ NOT ] DISTINCT ] ( <replaceable class="parameter">column_name</replaceable> [, ... ] [, <replaceable class="parameter">column_name</replaceable> WITHOUT OVERLAPS ] ) <replaceable class="parameter">index_parameters</replaceable> |
82
82
PRIMARY KEY ( <replaceable class="parameter">column_name</replaceable> [, ... ] [, <replaceable class="parameter">column_name</replaceable> WITHOUT OVERLAPS ] ) <replaceable class="parameter">index_parameters</replaceable> |
83
83
EXCLUDE [ USING <replaceable class="parameter">index_method</replaceable> ] ( <replaceable class="parameter">exclude_element</replaceable> WITH <replaceable class="parameter">operator</replaceable> [, ... ] ) <replaceable class="parameter">index_parameters</replaceable> [ WHERE ( <replaceable class="parameter">predicate</replaceable> ) ] |
84
- FOREIGN KEY ( <replaceable class="parameter">column_name</replaceable> [, ... ] ) REFERENCES <replaceable class="parameter">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</replaceable> [, ... ] ) ]
84
+ FOREIGN KEY ( <replaceable class="parameter">column_name</replaceable> [, ... ] [, PERIOD <replaceable class="parameter">column_name</replaceable> ] ) REFERENCES <replaceable class="parameter">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</replaceable> [, ... ] [, PERIOD <replaceable class="parameter">column_name</replaceable> ] ) ]
85
85
[ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ] [ ON DELETE <replaceable
86
86
class="parameter">referential_action</replaceable> ] [ ON UPDATE <replaceable class="parameter">referential_action</replaceable> ] }
87
87
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
@@ -1152,8 +1152,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
1152
1152
<varlistentry id="sql-createtable-parms-references">
1153
1153
<term><literal>REFERENCES <replaceable class="parameter">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</replaceable> ) ] [ MATCH <replaceable class="parameter">matchtype</replaceable> ] [ ON DELETE <replaceable class="parameter">referential_action</replaceable> ] [ ON UPDATE <replaceable class="parameter">referential_action</replaceable> ]</literal> (column constraint)</term>
1154
1154
1155
- <term><literal>FOREIGN KEY ( <replaceable class="parameter">column_name</replaceable> [, ... ] )
1156
- REFERENCES <replaceable class="parameter">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</replaceable> [, ... ] ) ]
1155
+ <term><literal>FOREIGN KEY ( <replaceable class="parameter">column_name</replaceable> [, ... ] [, PERIOD <replaceable class="parameter">column_name</replaceable> ] )
1156
+ REFERENCES <replaceable class="parameter">reftable</replaceable> [ ( <replaceable class="parameter">refcolumn</replaceable> [, ... ] [, PERIOD <replaceable class="parameter">column_name</replaceable> ] ) ]
1157
1157
[ MATCH <replaceable class="parameter">matchtype</replaceable> ]
1158
1158
[ ON DELETE <replaceable class="parameter">referential_action</replaceable> ]
1159
1159
[ ON UPDATE <replaceable class="parameter">referential_action</replaceable> ]</literal>
@@ -1169,7 +1169,30 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
1169
1169
primary key of the <replaceable class="parameter">reftable</replaceable>
1170
1170
is used. Otherwise, the <replaceable class="parameter">refcolumn</replaceable>
1171
1171
list must refer to the columns of a non-deferrable unique or primary key
1172
- constraint or be the columns of a non-partial unique index. The user
1172
+ constraint or be the columns of a non-partial unique index.
1173
+ </para>
1174
+
1175
+ <para>
1176
+ If the last column is marked with <literal>PERIOD</literal>, it is
1177
+ treated in a special way. While the non-<literal>PERIOD</literal>
1178
+ columns are compared for equality (and there must be at least one of
1179
+ them), the <literal>PERIOD</literal> column is not. Instead, the
1180
+ constraint is considered satisfied if the referenced table has matching
1181
+ records (based on the non-<literal>PERIOD</literal> parts of the key)
1182
+ whose combined <literal>PERIOD</literal> values completely cover the
1183
+ referencing record's. In other words, the reference must have a
1184
+ referent for its entire duration. This column must be a range or
1185
+ multirange type. In addition, the referenced table must have a primary
1186
+ key or unique constraint declared with <literal>WITHOUT
1187
+ OVERLAPS</literal>. Finally, if one side of the foreign key uses
1188
+ <literal>PERIOD</literal>, the other side must too. If the <replaceable
1189
+ class="parameter">refcolumn</replaceable> list is omitted, the
1190
+ <literal>WITHOUT OVERLAPS</literal> part of the primary key is treated
1191
+ as if marked with <literal>PERIOD</literal>.
1192
+ </para>
1193
+
1194
+ <para>
1195
+ The user
1173
1196
must have <literal>REFERENCES</literal> permission on the referenced
1174
1197
table (either the whole table, or the specific referenced columns). The
1175
1198
addition of a foreign key constraint requires a
@@ -1243,6 +1266,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
1243
1266
values of the referencing column(s) to the new values of the
1244
1267
referenced columns, respectively.
1245
1268
</para>
1269
+
1270
+ <para>
1271
+ In a temporal foreign key, this option is not supported.
1272
+ </para>
1246
1273
</listitem>
1247
1274
</varlistentry>
1248
1275
@@ -1254,6 +1281,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
1254
1281
referencing columns, to null. A subset of columns can only be
1255
1282
specified for <literal>ON DELETE</literal> actions.
1256
1283
</para>
1284
+
1285
+ <para>
1286
+ In a temporal foreign key, this option is not supported.
1287
+ </para>
1257
1288
</listitem>
1258
1289
</varlistentry>
1259
1290
@@ -1267,6 +1298,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
1267
1298
(There must be a row in the referenced table matching the default
1268
1299
values, if they are not null, or the operation will fail.)
1269
1300
</para>
1301
+
1302
+ <para>
1303
+ In a temporal foreign key, this option is not supported.
1304
+ </para>
1270
1305
</listitem>
1271
1306
</varlistentry>
1272
1307
</variablelist>
0 commit comments