Skip to content

Commit 594b526

Browse files
committed
Modify message when partitioned table is added to publication
Give a more specific error message than "xyz is not a table". Also document in CREATE PUBLICATION which kinds of relations are not supported. based on patch by Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
1 parent 3a66581 commit 594b526

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

doc/src/sgml/ref/create_publication.sgml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ CREATE PUBLICATION <replaceable class="parameter">name</replaceable>
7575
Optionally, <literal>*</> can be specified after the table name to
7676
explicitly indicate that descendant tables are included.
7777
</para>
78+
79+
<para>
80+
Only persistent base tables can be part of a publication. Temporary
81+
tables, unlogged tables, foreign tables, materialized views, regular
82+
views, and partitioned tables cannot be part of a publication. To
83+
replicate a partitioned table, add the individual partitions to the
84+
publication.
85+
</para>
7886
</listitem>
7987
</varlistentry>
8088

src/backend/catalog/pg_publication.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@
5050
static void
5151
check_publication_add_relation(Relation targetrel)
5252
{
53+
/* Give more specific error for partitioned tables */
54+
if (RelationGetForm(targetrel)->relkind == RELKIND_PARTITIONED_TABLE)
55+
ereport(ERROR,
56+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
57+
errmsg("\"%s\" is a partitioned table",
58+
RelationGetRelationName(targetrel)),
59+
errdetail("Adding partitioned tables to publications is not supported."),
60+
errhint("You can add the table partitions individually.")));
61+
5362
/* Must be table */
5463
if (RelationGetForm(targetrel)->relkind != RELKIND_RELATION)
5564
ereport(ERROR,

src/test/regress/expected/publication.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ CREATE SCHEMA pub_test;
3737
CREATE TABLE testpub_tbl1 (id serial primary key, data text);
3838
CREATE TABLE pub_test.testpub_nopk (foo int, bar int);
3939
CREATE VIEW testpub_view AS SELECT 1;
40+
CREATE TABLE testpub_parted (a int) PARTITION BY LIST (a);
4041
CREATE PUBLICATION testpub_foralltables FOR ALL TABLES WITH (nopublish delete, nopublish update);
4142
ALTER PUBLICATION testpub_foralltables WITH (publish update);
4243
CREATE TABLE testpub_tbl2 (id serial primary key, data text);
@@ -118,6 +119,11 @@ Tables:
118119
ALTER PUBLICATION testpub_default ADD TABLE testpub_view;
119120
ERROR: "testpub_view" is not a table
120121
DETAIL: Only tables can be added to publications.
122+
-- fail - partitioned table
123+
ALTER PUBLICATION testpub_fortbl ADD TABLE testpub_parted;
124+
ERROR: "testpub_parted" is a partitioned table
125+
DETAIL: Adding partitioned tables to publications is not supported.
126+
HINT: You can add the table partitions individually.
121127
ALTER PUBLICATION testpub_default ADD TABLE testpub_tbl1;
122128
ALTER PUBLICATION testpub_default SET TABLE testpub_tbl1;
123129
ALTER PUBLICATION testpub_default ADD TABLE pub_test.testpub_nopk;
@@ -188,6 +194,7 @@ ALTER PUBLICATION testpub2 ADD TABLE testpub_tbl1; -- ok
188194
DROP PUBLICATION testpub2;
189195
SET ROLE regress_publication_user;
190196
REVOKE CREATE ON DATABASE regression FROM regress_publication_user2;
197+
DROP TABLE testpub_parted;
191198
DROP VIEW testpub_view;
192199
DROP TABLE testpub_tbl1;
193200
\dRp+ testpub_default

src/test/regress/sql/publication.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ CREATE SCHEMA pub_test;
2626
CREATE TABLE testpub_tbl1 (id serial primary key, data text);
2727
CREATE TABLE pub_test.testpub_nopk (foo int, bar int);
2828
CREATE VIEW testpub_view AS SELECT 1;
29+
CREATE TABLE testpub_parted (a int) PARTITION BY LIST (a);
2930

3031
CREATE PUBLICATION testpub_foralltables FOR ALL TABLES WITH (nopublish delete, nopublish update);
3132
ALTER PUBLICATION testpub_foralltables WITH (publish update);
@@ -66,6 +67,8 @@ CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_tbl1;
6667

6768
-- fail - view
6869
ALTER PUBLICATION testpub_default ADD TABLE testpub_view;
70+
-- fail - partitioned table
71+
ALTER PUBLICATION testpub_fortbl ADD TABLE testpub_parted;
6972

7073
ALTER PUBLICATION testpub_default ADD TABLE testpub_tbl1;
7174
ALTER PUBLICATION testpub_default SET TABLE testpub_tbl1;
@@ -104,6 +107,7 @@ DROP PUBLICATION testpub2;
104107
SET ROLE regress_publication_user;
105108
REVOKE CREATE ON DATABASE regression FROM regress_publication_user2;
106109

110+
DROP TABLE testpub_parted;
107111
DROP VIEW testpub_view;
108112
DROP TABLE testpub_tbl1;
109113

0 commit comments

Comments
 (0)