@@ -23,7 +23,8 @@ PostgreSQL documentation
23
23
<synopsis>
24
24
CREATE FOREIGN TABLE [ IF NOT EXISTS ] <replaceable class="parameter">table_name</replaceable> ( [
25
25
{ <replaceable class="parameter">column_name</replaceable> <replaceable class="parameter">data_type</replaceable> [ OPTIONS ( <replaceable class="parameter">option</replaceable> '<replaceable class="parameter">value</replaceable>' [, ... ] ) ] [ COLLATE <replaceable>collation</replaceable> ] [ <replaceable class="parameter">column_constraint</replaceable> [ ... ] ]
26
- | <replaceable>table_constraint</replaceable> }
26
+ | <replaceable>table_constraint</replaceable>
27
+ | LIKE <replaceable>source_table</replaceable> [ <replaceable>like_option</replaceable> ... ] }
27
28
[, ... ]
28
29
] )
29
30
[ INHERITS ( <replaceable>parent_table</replaceable> [, ... ] ) ]
@@ -57,6 +58,10 @@ CREATE FOREIGN TABLE [ IF NOT EXISTS ] <replaceable class="parameter">table_name
57
58
CHECK ( <replaceable class="parameter">expression</replaceable> ) [ NO INHERIT ] }
58
59
[ ENFORCED | NOT ENFORCED ]
59
60
61
+ <phrase>and <replaceable class="parameter">like_option</replaceable> is:</phrase>
62
+
63
+ { INCLUDING | EXCLUDING } { COMMENTS | CONSTRAINTS | DEFAULTS | GENERATED | STATISTICS | ALL }
64
+
60
65
<phrase>and <replaceable class="parameter">partition_bound_spec</replaceable> is:</phrase>
61
66
62
67
IN ( <replaceable class="parameter">partition_bound_expr</replaceable> [, ...] ) |
@@ -191,6 +196,111 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
191
196
</listitem>
192
197
</varlistentry>
193
198
199
+ <varlistentry>
200
+ <term><literal>LIKE <replaceable>source_table</replaceable> [ <replaceable>like_option</replaceable> ... ]</literal></term>
201
+ <listitem>
202
+ <para>
203
+ The <literal>LIKE</literal> clause specifies a table from which
204
+ the new table automatically copies all column names, their data types,
205
+ and their not-null constraints.
206
+ </para>
207
+ <para>
208
+ Unlike <literal>INHERITS</literal>, the new table and original table
209
+ are completely decoupled after creation is complete. Changes to the
210
+ original table will not be applied to the new table, and it is not
211
+ possible to include data of the new table in scans of the original
212
+ table.
213
+ </para>
214
+ <para>
215
+ Also unlike <literal>INHERITS</literal>, columns and
216
+ constraints copied by <literal>LIKE</literal> are not merged with similarly
217
+ named columns and constraints.
218
+ If the same name is specified explicitly or in another
219
+ <literal>LIKE</literal> clause, an error is signaled.
220
+ </para>
221
+ <para>
222
+ The optional <replaceable>like_option</replaceable> clauses specify
223
+ which additional properties of the original table to copy. Specifying
224
+ <literal>INCLUDING</literal> copies the property, specifying
225
+ <literal>EXCLUDING</literal> omits the property.
226
+ <literal>EXCLUDING</literal> is the default. If multiple specifications
227
+ are made for the same kind of object, the last one is used. The
228
+ available options are:
229
+
230
+ <variablelist>
231
+ <varlistentry>
232
+ <term><literal>INCLUDING COMMENTS</literal></term>
233
+ <listitem>
234
+ <para>
235
+ Comments for the copied columns, constraints, and indexes will be
236
+ copied. The default behavior is to exclude comments, resulting in
237
+ the copied columns and constraints in the new table having no
238
+ comments.
239
+ </para>
240
+ </listitem>
241
+ </varlistentry>
242
+
243
+ <varlistentry>
244
+ <term><literal>INCLUDING CONSTRAINTS</literal></term>
245
+ <listitem>
246
+ <para>
247
+ <literal>CHECK</literal> constraints will be copied. No distinction
248
+ is made between column constraints and table constraints. Not-null
249
+ constraints are always copied to the new table.
250
+ </para>
251
+ </listitem>
252
+ </varlistentry>
253
+
254
+ <varlistentry>
255
+ <term><literal>INCLUDING DEFAULTS</literal></term>
256
+ <listitem>
257
+ <para>
258
+ Default expressions for the copied column definitions will be
259
+ copied. Otherwise, default expressions are not copied, resulting in
260
+ the copied columns in the new table having null defaults. Note that
261
+ copying defaults that call database-modification functions, such as
262
+ <function>nextval</function>, may create a functional linkage
263
+ between the original and new tables.
264
+ </para>
265
+ </listitem>
266
+ </varlistentry>
267
+
268
+ <varlistentry>
269
+ <term><literal>INCLUDING GENERATED</literal></term>
270
+ <listitem>
271
+ <para>
272
+ Any generation expressions of copied column definitions will be
273
+ copied. By default, new columns will be regular base columns.
274
+ </para>
275
+ </listitem>
276
+ </varlistentry>
277
+
278
+ <varlistentry>
279
+ <term><literal>INCLUDING STATISTICS</literal></term>
280
+ <listitem>
281
+ <para>
282
+ Extended statistics are copied to the new table.
283
+ </para>
284
+ </listitem>
285
+ </varlistentry>
286
+
287
+ <varlistentry>
288
+ <term><literal>INCLUDING ALL</literal></term>
289
+ <listitem>
290
+ <para>
291
+ <literal>INCLUDING ALL</literal> is an abbreviated form selecting
292
+ all the available individual options. (It could be useful to write
293
+ individual <literal>EXCLUDING</literal> clauses after
294
+ <literal>INCLUDING ALL</literal> to select all but some specific
295
+ options.)
296
+ </para>
297
+ </listitem>
298
+ </varlistentry>
299
+ </variablelist>
300
+ </para>
301
+ </listitem>
302
+ </varlistentry>
303
+
194
304
<varlistentry>
195
305
<term><literal>CONSTRAINT <replaceable class="parameter">constraint_name</replaceable></literal></term>
196
306
<listitem>
@@ -448,6 +558,8 @@ CREATE FOREIGN TABLE measurement_y2016m07
448
558
The ability to specify column default values is also
449
559
a <productname>PostgreSQL</productname> extension. Table inheritance, in the form
450
560
defined by <productname>PostgreSQL</productname>, is nonstandard.
561
+ The <literal>LIKE</literal> clause, as supported in this command, is
562
+ nonstandard.
451
563
</para>
452
564
453
565
</refsect1>
0 commit comments