Commit 594b526b authored by Peter Eisentraut's avatar Peter Eisentraut

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>
parent 3a66581d
...@@ -75,6 +75,14 @@ CREATE PUBLICATION <replaceable class="parameter">name</replaceable> ...@@ -75,6 +75,14 @@ CREATE PUBLICATION <replaceable class="parameter">name</replaceable>
Optionally, <literal>*</> can be specified after the table name to Optionally, <literal>*</> can be specified after the table name to
explicitly indicate that descendant tables are included. explicitly indicate that descendant tables are included.
</para> </para>
<para>
Only persistent base tables can be part of a publication. Temporary
tables, unlogged tables, foreign tables, materialized views, regular
views, and partitioned tables cannot be part of a publication. To
replicate a partitioned table, add the individual partitions to the
publication.
</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
......
...@@ -50,6 +50,15 @@ ...@@ -50,6 +50,15 @@
static void static void
check_publication_add_relation(Relation targetrel) check_publication_add_relation(Relation targetrel)
{ {
/* Give more specific error for partitioned tables */
if (RelationGetForm(targetrel)->relkind == RELKIND_PARTITIONED_TABLE)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("\"%s\" is a partitioned table",
RelationGetRelationName(targetrel)),
errdetail("Adding partitioned tables to publications is not supported."),
errhint("You can add the table partitions individually.")));
/* Must be table */ /* Must be table */
if (RelationGetForm(targetrel)->relkind != RELKIND_RELATION) if (RelationGetForm(targetrel)->relkind != RELKIND_RELATION)
ereport(ERROR, ereport(ERROR,
......
...@@ -37,6 +37,7 @@ CREATE SCHEMA pub_test; ...@@ -37,6 +37,7 @@ CREATE SCHEMA pub_test;
CREATE TABLE testpub_tbl1 (id serial primary key, data text); CREATE TABLE testpub_tbl1 (id serial primary key, data text);
CREATE TABLE pub_test.testpub_nopk (foo int, bar int); CREATE TABLE pub_test.testpub_nopk (foo int, bar int);
CREATE VIEW testpub_view AS SELECT 1; CREATE VIEW testpub_view AS SELECT 1;
CREATE TABLE testpub_parted (a int) PARTITION BY LIST (a);
CREATE PUBLICATION testpub_foralltables FOR ALL TABLES WITH (nopublish delete, nopublish update); CREATE PUBLICATION testpub_foralltables FOR ALL TABLES WITH (nopublish delete, nopublish update);
ALTER PUBLICATION testpub_foralltables WITH (publish update); ALTER PUBLICATION testpub_foralltables WITH (publish update);
CREATE TABLE testpub_tbl2 (id serial primary key, data text); CREATE TABLE testpub_tbl2 (id serial primary key, data text);
...@@ -118,6 +119,11 @@ Tables: ...@@ -118,6 +119,11 @@ Tables:
ALTER PUBLICATION testpub_default ADD TABLE testpub_view; ALTER PUBLICATION testpub_default ADD TABLE testpub_view;
ERROR: "testpub_view" is not a table ERROR: "testpub_view" is not a table
DETAIL: Only tables can be added to publications. DETAIL: Only tables can be added to publications.
-- fail - partitioned table
ALTER PUBLICATION testpub_fortbl ADD TABLE testpub_parted;
ERROR: "testpub_parted" is a partitioned table
DETAIL: Adding partitioned tables to publications is not supported.
HINT: You can add the table partitions individually.
ALTER PUBLICATION testpub_default ADD TABLE testpub_tbl1; ALTER PUBLICATION testpub_default ADD TABLE testpub_tbl1;
ALTER PUBLICATION testpub_default SET TABLE testpub_tbl1; ALTER PUBLICATION testpub_default SET TABLE testpub_tbl1;
ALTER PUBLICATION testpub_default ADD TABLE pub_test.testpub_nopk; ALTER PUBLICATION testpub_default ADD TABLE pub_test.testpub_nopk;
...@@ -188,6 +194,7 @@ ALTER PUBLICATION testpub2 ADD TABLE testpub_tbl1; -- ok ...@@ -188,6 +194,7 @@ ALTER PUBLICATION testpub2 ADD TABLE testpub_tbl1; -- ok
DROP PUBLICATION testpub2; DROP PUBLICATION testpub2;
SET ROLE regress_publication_user; SET ROLE regress_publication_user;
REVOKE CREATE ON DATABASE regression FROM regress_publication_user2; REVOKE CREATE ON DATABASE regression FROM regress_publication_user2;
DROP TABLE testpub_parted;
DROP VIEW testpub_view; DROP VIEW testpub_view;
DROP TABLE testpub_tbl1; DROP TABLE testpub_tbl1;
\dRp+ testpub_default \dRp+ testpub_default
......
...@@ -26,6 +26,7 @@ CREATE SCHEMA pub_test; ...@@ -26,6 +26,7 @@ CREATE SCHEMA pub_test;
CREATE TABLE testpub_tbl1 (id serial primary key, data text); CREATE TABLE testpub_tbl1 (id serial primary key, data text);
CREATE TABLE pub_test.testpub_nopk (foo int, bar int); CREATE TABLE pub_test.testpub_nopk (foo int, bar int);
CREATE VIEW testpub_view AS SELECT 1; CREATE VIEW testpub_view AS SELECT 1;
CREATE TABLE testpub_parted (a int) PARTITION BY LIST (a);
CREATE PUBLICATION testpub_foralltables FOR ALL TABLES WITH (nopublish delete, nopublish update); CREATE PUBLICATION testpub_foralltables FOR ALL TABLES WITH (nopublish delete, nopublish update);
ALTER PUBLICATION testpub_foralltables WITH (publish update); ALTER PUBLICATION testpub_foralltables WITH (publish update);
...@@ -66,6 +67,8 @@ CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_tbl1; ...@@ -66,6 +67,8 @@ CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_tbl1;
-- fail - view -- fail - view
ALTER PUBLICATION testpub_default ADD TABLE testpub_view; ALTER PUBLICATION testpub_default ADD TABLE testpub_view;
-- fail - partitioned table
ALTER PUBLICATION testpub_fortbl ADD TABLE testpub_parted;
ALTER PUBLICATION testpub_default ADD TABLE testpub_tbl1; ALTER PUBLICATION testpub_default ADD TABLE testpub_tbl1;
ALTER PUBLICATION testpub_default SET TABLE testpub_tbl1; ALTER PUBLICATION testpub_default SET TABLE testpub_tbl1;
...@@ -104,6 +107,7 @@ DROP PUBLICATION testpub2; ...@@ -104,6 +107,7 @@ DROP PUBLICATION testpub2;
SET ROLE regress_publication_user; SET ROLE regress_publication_user;
REVOKE CREATE ON DATABASE regression FROM regress_publication_user2; REVOKE CREATE ON DATABASE regression FROM regress_publication_user2;
DROP TABLE testpub_parted;
DROP VIEW testpub_view; DROP VIEW testpub_view;
DROP TABLE testpub_tbl1; DROP TABLE testpub_tbl1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment