From 005f7e4d8499b1caa2d95304479237503e1058e9 Mon Sep 17 00:00:00 2001
From: amit <amitlangote09@gmail.com>
Date: Tue, 18 Apr 2017 14:03:29 +0900
Subject: [PATCH] Modify message when partitioned table is added to publication

---
 src/backend/catalog/pg_publication.c      | 8 ++++++++
 src/test/regress/expected/publication.out | 6 ++++++
 src/test/regress/sql/publication.sql      | 5 +++++
 3 files changed, 19 insertions(+)

diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c
index 9330e2380a..139fc7d632 100644
--- a/src/backend/catalog/pg_publication.c
+++ b/src/backend/catalog/pg_publication.c
@@ -50,6 +50,14 @@
 static void
 check_publication_add_relation(Relation targetrel)
 {
+	/* Handle partitioned tables explicitly */
+	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.")));
+
 	/* Must be table */
 	if (RelationGetForm(targetrel)->relkind != RELKIND_RELATION)
 		ereport(ERROR,
diff --git a/src/test/regress/expected/publication.out b/src/test/regress/expected/publication.out
index 5b7fb674da..cedec3b0e2 100644
--- a/src/test/regress/expected/publication.out
+++ b/src/test/regress/expected/publication.out
@@ -228,3 +228,9 @@ NOTICE:  drop cascades to table pub_test.testpub_nopk
 RESET SESSION AUTHORIZATION;
 DROP ROLE regress_publication_user, regress_publication_user2;
 DROP ROLE regress_publication_user_dummy;
+-- cannot publish partitioned tables
+CREATE TABLE nopublish_parted (a int) PARTITION BY LIST (a);
+CREATE PUBLICATION nopublish_parted_pub FOR TABLE nopublish_parted;
+ERROR:  "nopublish_parted" is a partitioned table
+DETAIL:  Adding partitioned tables to publications is not supported.
+DROP TABLE nopublish_parted;
diff --git a/src/test/regress/sql/publication.sql b/src/test/regress/sql/publication.sql
index b118bc9906..3a7ccb0770 100644
--- a/src/test/regress/sql/publication.sql
+++ b/src/test/regress/sql/publication.sql
@@ -134,3 +134,8 @@ DROP SCHEMA pub_test CASCADE;
 RESET SESSION AUTHORIZATION;
 DROP ROLE regress_publication_user, regress_publication_user2;
 DROP ROLE regress_publication_user_dummy;
+
+-- cannot publish partitioned tables
+CREATE TABLE nopublish_parted (a int) PARTITION BY LIST (a);
+CREATE PUBLICATION nopublish_parted_pub FOR TABLE nopublish_parted;
+DROP TABLE nopublish_parted;
-- 
2.11.0

