From 1b6833ca809895796b56c0c62375a1b416951618 Mon Sep 17 00:00:00 2001
From: Manu <manuelreyesbravo@gmail.com>
Date: Wed, 16 Sep 2026 09:35:09 -0300
Subject: [PATCH v2 on top of v5 1/2] Qualify the relation name in publication
 relation object address errors

get_object_address_publication_rel() reports the relation by its bare
name in its four errors.  When the relation was given without a schema,
the message does not say which one the search_path picked:

    CREATE SCHEMA s1; CREATE TABLE s1.t2(a int);
    CREATE SCHEMA s2; CREATE TABLE s2.t2(a int);
    CREATE PUBLICATION pub FOR TABLE s1.t2;
    SET search_path = s2;
    SELECT pg_get_object_address('publication relation', '{t2}', '{pub}');
    ERROR:  publication relation "t2" in publication "pub" does not exist

Report the schema as well, as commit a49b9cfd72d did for the EXCEPT
clause errors, using the "\"%s.%s\"" form common in the backend rather
than a quoted qualified name inside quotes.
---
 src/backend/catalog/objectaddress.c       | 12 ++++++++----
 src/test/regress/expected/publication.out |  6 +++---
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c
index 1e24f4b80be..a97107d8529 100644
--- a/src/backend/catalog/objectaddress.c
+++ b/src/backend/catalog/objectaddress.c
@@ -1923,12 +1923,14 @@ get_object_address_publication_rel(ObjectType objtype, List *object,
 			if (objtype == OBJECT_PUBLICATION_EXCLUDED_REL)
 				ereport(ERROR,
 						(errcode(ERRCODE_UNDEFINED_OBJECT),
-						 errmsg("publication excluded relation \"%s\" in publication \"%s\" does not exist",
+						 errmsg("publication excluded relation \"%s.%s\" in publication \"%s\" does not exist",
+								get_namespace_name(RelationGetNamespace(relation)),
 								RelationGetRelationName(relation), pubname)));
 			else
 				ereport(ERROR,
 						(errcode(ERRCODE_UNDEFINED_OBJECT),
-						 errmsg("publication relation \"%s\" in publication \"%s\" does not exist",
+						 errmsg("publication relation \"%s.%s\" in publication \"%s\" does not exist",
+								get_namespace_name(RelationGetNamespace(relation)),
 								RelationGetRelationName(relation), pubname)));
 		}
 		relation_close(relation, AccessShareLock);
@@ -1948,12 +1950,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..3013e405422 100644
--- a/src/test/regress/expected/publication.out
+++ b/src/test/regress/expected/publication.out
@@ -288,15 +288,15 @@ 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}');
-ERROR:  publication excluded relation "testpub_tbl1" in publication "testpub_default" does not exist
+ERROR:  publication excluded relation "public.testpub_tbl1" in publication "testpub_default" does not exist
 -- Check pg_describe_object output for both included and excluded entries
 SELECT p.pubname,
        pg_describe_object('pg_publication_rel'::regclass, pr.oid, 0) AS description,
-- 
2.55.0

