Skip to content

Commit cbadfc1

Browse files
committed
Doc: be clearer that foreign-table partitions need user-added constraints.
A very well-informed user might deduce this from what we said already, but I'd bet against it. Lay it out explicitly. While here, rewrite the comment about tuple routing to be more intelligible to an average SQL user. Per bug #17395 from Alexander Lakhin. Back-patch to v11. (The text in this area is different in v10 and I'm not sufficiently excited about this point to adapt the patch.) Discussion: https://postgr.es/m/17395-8c326292078d1a57@postgresql.org
1 parent 5e26aa6 commit cbadfc1

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

doc/src/sgml/ddl.sgml

+6-3
Original file line numberDiff line numberDiff line change
@@ -3791,9 +3791,12 @@ VALUES ('Albany', NULL, NULL, 'NY');
37913791
</para>
37923792

37933793
<para>
3794-
Partitions can also be foreign tables, although they have some limitations
3795-
that normal tables do not; see <xref linkend="sql-createforeigntable"/> for
3796-
more information.
3794+
Partitions can also be <link linkend="ddl-foreign-data">foreign
3795+
tables</link>, although considerable care is needed because it is then
3796+
the user's responsibility that the contents of the foreign table
3797+
satisfy the partitioning rule. There are some other restrictions as
3798+
well. See <xref linkend="sql-createforeigntable"/> for more
3799+
information.
37973800
</para>
37983801

37993802
<sect3 id="ddl-partitioning-declarative-example">

doc/src/sgml/ref/create_foreign_table.sgml

+23-7
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,33 @@ CHECK ( <replaceable class="parameter">expression</replaceable> ) [ NO INHERIT ]
348348
constraints on foreign tables, it does assume that they are correct
349349
for purposes of query optimization. If there are rows visible in the
350350
foreign table that do not satisfy a declared constraint, queries on
351-
the table might produce incorrect answers. It is the user's
351+
the table might produce errors or incorrect answers. It is the user's
352352
responsibility to ensure that the constraint definition matches
353353
reality.
354354
</para>
355355

356+
<caution>
357+
<para>
358+
When a foreign table is used as a partition of a partitioned table,
359+
there is an implicit constraint that its contents must satisfy the
360+
partitioning rule. Again, it is the user's responsibility to ensure
361+
that that is true, which is best done by installing a matching
362+
constraint on the remote server.
363+
</para>
364+
</caution>
365+
366+
<para>
367+
Within a partitioned table containing foreign-table partitions,
368+
an <command>UPDATE</command> that changes the partition key value can
369+
cause a row to be moved from a local partition to a foreign-table
370+
partition, provided the foreign data wrapper supports tuple routing.
371+
However it is not currently possible to move a row from a
372+
foreign-table partition to another partition.
373+
An <command>UPDATE</command> that would require doing that will fail
374+
due to the partitioning constraint, assuming that that is properly
375+
enforced by the remote server.
376+
</para>
377+
356378
<para>
357379
Similar considerations apply to generated columns. Stored generated
358380
columns are computed on insert or update on the local
@@ -362,12 +384,6 @@ CHECK ( <replaceable class="parameter">expression</replaceable> ) [ NO INHERIT ]
362384
generated columns that are consistent with the generation expression.
363385
Again, this might result in incorrect query results.
364386
</para>
365-
366-
<para>
367-
While rows can be moved from local partitions to a foreign-table partition
368-
(provided the foreign data wrapper supports tuple routing), they cannot be
369-
moved from a foreign-table partition to another partition.
370-
</para>
371387
</refsect1>
372388

373389
<refsect1 id="sql-createforeigntable-examples">

0 commit comments

Comments
 (0)