1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

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 <manuelreyesbravo@gmail.com>
Reviewed-by: shveta malik <shveta.malik@gmail.com>
Reviewed-by: Vignesh C <vignesh21@gmail.com>
Reviewed-by: Peter Smith <smithpb2250@gmail.com>
Reviewed-by: Zhijie Hou <houzj.fnst@fujitsu.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwHfESBexa7fq99EvFCf31av=O9h9udnw22ymxmm6LMZzw@mail.gmail.com
Backpatch-through: 19, where it was introduced
This commit is contained in:
Amit Kapila
2026-09-18 10:50:25 +05:30
parent 73b0b18f1f
commit 644e00f7f2
5 changed files with 17 additions and 14 deletions

View File

@@ -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

View File

@@ -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
* ----------------------------------------------------------------

View File

@@ -46,7 +46,6 @@ AssertCouldGetRelation(void)
}
#endif
extern Relation RelationIdGetRelation(Oid relationId);
extern char *RelationGetQualifiedRelationName(Relation rel);
extern void RelationClose(Relation relation);
/*

View File

@@ -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;

View File

@@ -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