From df48fd8388ead308b98a672a823930464b4ef94f Mon Sep 17 00:00:00 2001
From: Vignesh C <vignesh21@gmail.com>
Date: Mon, 16 Mar 2026 15:48:45 +0530
Subject: [PATCH] Fix few issues in commit fd366065e0

Improve documentation wording to clarify behavior when a subscription
includes multiple publications, particularly when tables or partitions
are excluded via the EXCEPT TABLE clause. Adjust the description to
reflect that partitions may be excluded implicitly through their parent.

Refine error message in check_publication_add_relation() to improve
clarity when a relation is specified in the publication EXCEPT clause.

Also fix naming inconsistencies in subscription tests (tab_* vs tap_*)
and update an incorrect test comment to reflect that only tables are
created, not schemas.
---
 doc/src/sgml/ref/create_publication.sgml  |  5 +++--
 src/backend/catalog/pg_publication.c      |  2 +-
 src/test/regress/expected/publication.out |  2 +-
 src/test/subscription/t/037_except.pl     | 18 +++++++++---------
 4 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/doc/src/sgml/ref/create_publication.sgml b/doc/src/sgml/ref/create_publication.sgml
index 77066ef680b..84777348759 100644
--- a/doc/src/sgml/ref/create_publication.sgml
+++ b/doc/src/sgml/ref/create_publication.sgml
@@ -214,8 +214,9 @@ CREATE PUBLICATION <replaceable class="parameter">name</replaceable>
      <para>
       There can be a case where a subscription includes multiple publications.
       In such a case, a table or partition that is included in one publication
-      and listed in the <literal>EXCEPT TABLE</literal> clause of another is
-      considered included for replication.
+      but excluded (explicitly or implicitly) by the
+      <literal>EXCEPT TABLE</literal> clause of another is considered included
+      for replication.
      </para>
     </listitem>
    </varlistentry>
diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c
index a79157c43bf..3a3a37817c6 100644
--- a/src/backend/catalog/pg_publication.c
+++ b/src/backend/catalog/pg_publication.c
@@ -59,7 +59,7 @@ check_publication_add_relation(PublicationRelInfo *pri)
 	const char *errormsg;
 
 	if (pri->except)
-		errormsg = gettext_noop("cannot use publication EXCEPT clause for relation \"%s\"");
+		errormsg = gettext_noop("cannot specify relation \"%s\" in the publication EXCEPT clause");
 	else
 		errormsg = gettext_noop("cannot add relation \"%s\" to publication");
 
diff --git a/src/test/regress/expected/publication.out b/src/test/regress/expected/publication.out
index 681d2564ed5..de2bd4d443e 100644
--- a/src/test/regress/expected/publication.out
+++ b/src/test/regress/expected/publication.out
@@ -353,7 +353,7 @@ Except Publications:
 Number of partitions: 1 (Use \d+ to list them.)
 
 CREATE PUBLICATION testpub9 FOR ALL TABLES EXCEPT TABLE (testpub_part1);
-ERROR:  cannot use publication EXCEPT clause for relation "testpub_part1"
+ERROR:  cannot specify relation "testpub_part1" in the publication EXCEPT clause
 DETAIL:  This operation is not supported for individual partitions.
 CREATE TABLE tab_main (a int) PARTITION BY RANGE(a);
 -- Attaching a partition is not allowed if the partitioned table appears in a
diff --git a/src/test/subscription/t/037_except.pl b/src/test/subscription/t/037_except.pl
index 2729df4d5c0..5159bb5a03a 100644
--- a/src/test/subscription/t/037_except.pl
+++ b/src/test/subscription/t/037_except.pl
@@ -70,7 +70,7 @@ sub test_except_root_partition
 # EXCEPT TABLE test cases for non-partitioned tables and inherited tables.
 # ============================================
 
-# Create schemas and tables on publisher
+# Create tables on publisher
 $node_publisher->safe_psql(
 	'postgres', qq(
 	CREATE TABLE tab1 AS SELECT generate_series(1,10) AS a;
@@ -80,7 +80,7 @@ $node_publisher->safe_psql(
 	CREATE TABLE child1 (b int) INHERITS (parent1);
 ));
 
-# Create schemas and tables on subscriber
+# Create tables on subscriber
 $node_subscriber->safe_psql(
 	'postgres', qq(
 	CREATE TABLE tab1 (a int);
@@ -94,7 +94,7 @@ $node_subscriber->safe_psql(
 # to verify exclusion behavior for inherited tables, including the effect of
 # ONLY in the EXCEPT TABLE clause.
 $node_publisher->safe_psql('postgres',
-	"CREATE PUBLICATION tab_pub FOR ALL TABLES EXCEPT TABLE (tab1, parent, only parent1)"
+	"CREATE PUBLICATION tap_pub FOR ALL TABLES EXCEPT TABLE (tab1, parent, only parent1)"
 );
 
 # Create a logical replication slot to help with later tests.
@@ -102,11 +102,11 @@ $node_publisher->safe_psql('postgres',
 	"SELECT pg_create_logical_replication_slot('test_slot', 'pgoutput')");
 
 $node_subscriber->safe_psql('postgres',
-	"CREATE SUBSCRIPTION tab_sub CONNECTION '$publisher_connstr' PUBLICATION tab_pub"
+	"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub"
 );
 
 # Wait for initial table sync to finish
-$node_subscriber->wait_for_subscription_sync($node_publisher, 'tab_sub');
+$node_subscriber->wait_for_subscription_sync($node_publisher, 'tap_sub');
 
 # Check the table data does not sync for the tables specified in EXCEPT TABLE
 # clause.
@@ -126,7 +126,7 @@ $node_publisher->safe_psql(
 # Verify that data inserted into a table listed in the EXCEPT TABLE clause is
 # not published.
 $result = $node_publisher->safe_psql('postgres',
-	"SELECT count(*) = 0 FROM pg_logical_slot_get_binary_changes('test_slot', NULL, NULL, 'proto_version', '1', 'publication_names', 'tab_pub')"
+	"SELECT count(*) = 0 FROM pg_logical_slot_get_binary_changes('test_slot', NULL, NULL, 'proto_version', '1', 'publication_names', 'tap_pub')"
 );
 is($result, qq(t),
 	'verify no changes for table listed in the EXCEPT TABLE clause are present in the replication slot'
@@ -141,7 +141,7 @@ $node_publisher->safe_psql('postgres',
 
 # Verify that data inserted into a table listed in the EXCEPT TABLE clause is
 # not replicated.
-$node_publisher->wait_for_catchup('tab_sub');
+$node_publisher->wait_for_catchup('tap_sub');
 $result =
   $node_subscriber->safe_psql('postgres', "SELECT count(*) FROM tab1");
 is($result, qq(0), 'check replicated inserts on subscriber');
@@ -155,13 +155,13 @@ is($result, qq(10), 'check replicated inserts on subscriber');
 # cleanup
 $node_subscriber->safe_psql(
 	'postgres', qq(
-	DROP SUBSCRIPTION tab_sub;
+	DROP SUBSCRIPTION tap_sub;
 	TRUNCATE TABLE tab1;
 	DROP TABLE parent, parent1, child, child1;
 ));
 $node_publisher->safe_psql(
 	'postgres', qq(
-	DROP PUBLICATION tab_pub;
+	DROP PUBLICATION tap_pub;
 	TRUNCATE TABLE tab1;
     DROP TABLE parent, parent1, child, child1;
 ));
-- 
2.43.0

