Hi,

Amit asked for an example where the message says a relation is not part
of the publication while it is.  Peter's example goes through the
pre-existing path; here is one inside the new code:

    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"

    SELECT schemaname, tablename FROM pg_publication_tables
     WHERE pubname = 'pub';
     schemaname | tablename
    ------------+-----------
     public     | t2

So the message says that "t2" is not a published relation of pub, while
the catalog says that a t2 is.  They are different tables, and the user
cannot tell which one the message is about.

Attached is a small patch on top of v5 that reports the schema too, in
the form publicationcmds.c already uses for its own messages:

    errmsg("cannot use column list for relation \"%s.%s\" in
publication \"%s\"",
           get_namespace_name(RelationGetNamespace(pri->relation)),
           RelationGetRelationName(pri->relation), pubname)

With it:

    ERROR:  "s2.t2" is not a published relation of publication "pub"

It only touches the two "is not a ... relation of publication" messages,
which are the ones reached when the relation does have an entry.  The
"does not exist" messages, including the new one for excluded relations
in v5, keep the unqualified form of the existing message they sit next
to.  `make check` passes with v5 plus this patch; publication.out is
updated for the two messages.

On the rest of the patch: I applied v4 to master at 04c4c1c3a96, built
with --enable-cassert and exercised the new object type by hand.  All
239 tests pass, pg_identify_object_as_address() reports "publication
excluded relation", the identify/address round trip works, and
pg_describe_object() gives "exclusion of table t2 from publication pub".
Asking for the wrong kind is rejected as intended, in both directions.
I did not find a functional problem.  v5 applies cleanly on the same
commit and passes as well.

Separately, I will start the thread shveta suggested for the case Peter
ran into with FOR ALL TABLES.  I have a patch for it that adds a detail
only when the table really is published, and I measured that it also
reproduces back to 13.

Regards,
Manu

El mié, 16 sept 2026 a las 5:57, vignesh C (<[email protected]>) escribió:
>
> On Wed, 16 Sept 2026 at 13:57, Chao Li <[email protected]> wrote:
> >
> > I don’t think the fix would add much complexity, please see the attached 
> > diff I tried. This error message is shown to users, so I think improving it 
> > is worthwhile.
>
> Agreed. I had initially thought the additional code complexity was not
> worthwhile. Since this is a user-facing error message, I agree that
> making it more specific is worthwhile. Thanks, I have merged the
> changes.
> The attached v5 version patch has the changes for the same.
>
> Regards,
> Vignesh
From d6cc354738b58a7c1a371c94189e7284c97929d2 Mon Sep 17 00:00:00 2001
From: Manu <[email protected]>
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

Reply via email to