From d6cc354738b58a7c1a371c94189e7284c97929d2 Mon Sep 17 00:00:00 2001
From: Manu <manuelreyesbravo@gmail.com>
Date: Wed, 16 Sep 2026 05:31:41 -0300
Subject: [PATCH delta on v5] Qualify the relation name in the new publication
 object address errors

A publication can hold tables of the same name in different schemas, so
the unqualified name in these two messages does not identify which table
is meant.  It can also contradict the catalog:

    CREATE TABLE t2(a int);
    CREATE SCHEMA s2; CREATE TABLE s2.t2(a int);
    CREATE PUBLICATION pub FOR ALL TABLES EXCEPT (TABLE s2.t2);

    SELECT pg_get_object_address('publication relation','{s2,t2}','{pub}');
    ERROR:  "t2" is not a published relation of publication "pub"

while pg_publication_tables reports that public.t2 is published by pub.

Report the schema as well, as the publication code already does for its
own messages in publicationcmds.c.
---
 src/backend/catalog/objectaddress.c       | 6 ++++--
 src/test/regress/expected/publication.out | 4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c
index 1e24f4b80be..85634f9c3fc 100644
--- a/src/backend/catalog/objectaddress.c
+++ b/src/backend/catalog/objectaddress.c
@@ -1948,12 +1948,14 @@ get_object_address_publication_rel(ObjectType objtype, List *object,
 	if (objtype == OBJECT_PUBLICATION_EXCLUDED_REL && !isexcept)
 		ereport(ERROR,
 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
-				 errmsg("\"%s\" is not an excluded relation of publication \"%s\"",
+				 errmsg("\"%s.%s\" is not an excluded relation of publication \"%s\"",
+						get_namespace_name(RelationGetNamespace(relation)),
 						RelationGetRelationName(relation), pubname)));
 	else if (objtype == OBJECT_PUBLICATION_REL && isexcept)
 		ereport(ERROR,
 				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
-				 errmsg("\"%s\" is not a published relation of publication \"%s\"",
+				 errmsg("\"%s.%s\" is not a published relation of publication \"%s\"",
+						get_namespace_name(RelationGetNamespace(relation)),
 						RelationGetRelationName(relation), pubname)));
 
 	*relp = relation;
diff --git a/src/test/regress/expected/publication.out b/src/test/regress/expected/publication.out
index d51b27d7d02..70f78428bd0 100644
--- a/src/test/regress/expected/publication.out
+++ b/src/test/regress/expected/publication.out
@@ -288,11 +288,11 @@ publication excluded relation|||public.testpub_tbl1 excluded from publication te
 CREATE PUBLICATION testpub_describe FOR TABLE testpub_tbl1;
 SELECT pg_get_object_address('publication excluded relation',
                              '{public, testpub_tbl1}', '{testpub_describe}');
-ERROR:  "testpub_tbl1" is not an excluded relation of publication "testpub_describe"
+ERROR:  "public.testpub_tbl1" is not an excluded relation of publication "testpub_describe"
 SELECT pg_get_object_address('publication relation',
                              '{public, testpub_tbl1}',
                              '{testpub_foralltables_excepttable1}');
-ERROR:  "testpub_tbl1" is not a published relation of publication "testpub_foralltables_excepttable1"
+ERROR:  "public.testpub_tbl1" is not a published relation of publication "testpub_foralltables_excepttable1"
 -- No entry of either kind.  testpub_default publishes nothing.
 SELECT pg_get_object_address('publication excluded relation',
                              '{public, testpub_tbl1}', '{testpub_default}');
-- 
2.55.0

