From 644e00f7f2dc992ed368eac37693be5458b869d9 Mon Sep 17 00:00:00 2001 From: Amit Kapila Date: Fri, 18 Sep 2026 10:50:25 +0530 Subject: [PATCH] Don't quote the relation name twice in EXCEPT clause errors. Commit a49b9cfd72 began reporting the EXCEPT clause relation with a schema-qualified name that quotes identifiers when needed, inside a message that already puts the name in quotes. So a schema or relation name that needs quoting came out quoted twice. Fix by building the qualified name as "%s.%s" without identifier quoting, so it renders like the qualified names in other backend error messages. The message text, and so its translations, is unchanged. RelationGetQualifiedRelationName() has no callers left, so remove it. Author: Manuel Reyes Bravo Reviewed-by: shveta malik Reviewed-by: Vignesh C Reviewed-by: Peter Smith Reviewed-by: Zhijie Hou Reviewed-by: Amit Kapila Discussion: https://postgr.es/m/CAHGQGwHfESBexa7fq99EvFCf31av=O9h9udnw22ymxmm6LMZzw@mail.gmail.com Backpatch-through: 19, where it was introduced --- src/backend/catalog/pg_publication.c | 8 +++++++- src/backend/utils/cache/relcache.c | 10 ---------- src/include/utils/relcache.h | 1 - src/test/regress/expected/publication.out | 7 ++++++- src/test/regress/sql/publication.sql | 5 ++++- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index a480d7924d9..fdd193c66ab 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -62,7 +62,13 @@ check_publication_add_relation(PublicationRelInfo *pri) if (pri->except) { - relname = RelationGetQualifiedRelationName(targetrel); + /* + * The name parts must not be quoted here, because the message already + * encloses the whole name in double quotes. + */ + relname = psprintf("%s.%s", + get_namespace_name(RelationGetNamespace(targetrel)), + RelationGetRelationName(targetrel)); errormsg = gettext_noop("cannot specify relation \"%s\" in the publication EXCEPT clause"); } else diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 55d5ec94e0a..ef5202091fb 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -2139,16 +2139,6 @@ RelationIdGetRelation(Oid relationId) return rd; } -/* - * Returns a schema-qualified name of the relation. - */ -char * -RelationGetQualifiedRelationName(Relation rel) -{ - return get_qualified_objname(RelationGetNamespace(rel), - RelationGetRelationName(rel)); -} - /* ---------------------------------------------------------------- * cache invalidation support routines * ---------------------------------------------------------------- diff --git a/src/include/utils/relcache.h b/src/include/utils/relcache.h index 89c27aa1529..2700224939a 100644 --- a/src/include/utils/relcache.h +++ b/src/include/utils/relcache.h @@ -46,7 +46,6 @@ AssertCouldGetRelation(void) } #endif extern Relation RelationIdGetRelation(Oid relationId); -extern char *RelationGetQualifiedRelationName(Relation rel); extern void RelationClose(Relation relation); /* diff --git a/src/test/regress/expected/publication.out b/src/test/regress/expected/publication.out index 81b767cae11..1abd8d99f1c 100644 --- a/src/test/regress/expected/publication.out +++ b/src/test/regress/expected/publication.out @@ -505,6 +505,11 @@ Number of partitions: 1 (Use \d+ to list them.) CREATE PUBLICATION testpub9 FOR ALL TABLES EXCEPT (TABLE testpub_part1); ERROR: cannot specify relation "public.testpub_part1" in the publication EXCEPT clause DETAIL: This operation is not supported for individual partitions. +-- A name that needs quoting must not be quoted twice in the message. +CREATE TABLE "testpub Part2" PARTITION OF testpub_root FOR VALUES FROM (100) TO (200); +CREATE PUBLICATION testpub9 FOR ALL TABLES EXCEPT (TABLE "testpub Part2"); +ERROR: cannot specify relation "public.testpub Part2" 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 -- publication's EXCEPT clause. @@ -513,7 +518,7 @@ ERROR: cannot attach table "testpub_root" as partition because it is referenced DETAIL: The publication EXCEPT clause cannot contain tables that are partitions. HINT: Change the publication's EXCEPT clause using ALTER PUBLICATION ... SET ALL TABLES. RESET client_min_messages; -DROP TABLE testpub_root, testpub_part1, tab_main; +DROP TABLE testpub_root, testpub_part1, "testpub Part2", tab_main; DROP PUBLICATION testpub8; --- Tests for publications with SEQUENCES CREATE SEQUENCE regress_pub_seq0; diff --git a/src/test/regress/sql/publication.sql b/src/test/regress/sql/publication.sql index 507ba2255b0..8fcf374b597 100644 --- a/src/test/regress/sql/publication.sql +++ b/src/test/regress/sql/publication.sql @@ -247,6 +247,9 @@ CREATE PUBLICATION testpub8 FOR ALL TABLES EXCEPT (TABLE testpub_root); \d testpub_part1 \d testpub_root CREATE PUBLICATION testpub9 FOR ALL TABLES EXCEPT (TABLE testpub_part1); +-- A name that needs quoting must not be quoted twice in the message. +CREATE TABLE "testpub Part2" PARTITION OF testpub_root FOR VALUES FROM (100) TO (200); +CREATE PUBLICATION testpub9 FOR ALL TABLES EXCEPT (TABLE "testpub Part2"); CREATE TABLE tab_main (a int) PARTITION BY RANGE(a); -- Attaching a partition is not allowed if the partitioned table appears in a @@ -254,7 +257,7 @@ CREATE TABLE tab_main (a int) PARTITION BY RANGE(a); ALTER TABLE tab_main ATTACH PARTITION testpub_root FOR VALUES FROM (0) TO (200); RESET client_min_messages; -DROP TABLE testpub_root, testpub_part1, tab_main; +DROP TABLE testpub_root, testpub_part1, "testpub Part2", tab_main; DROP PUBLICATION testpub8; --- Tests for publications with SEQUENCES