Re: Distinguish publication exclusions in object addresses

From: shveta malik <shveta(dot)malik(at)gmail(dot)com>
To: Peter Smith <smithpb2250(at)gmail(dot)com>
Cc: vignesh C <vignesh21(at)gmail(dot)com>, "Zhijie Hou (Fujitsu)" <houzj(dot)fnst(at)fujitsu(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Manuel Reyes Bravo <manuelreyesbravo(at)gmail(dot)com>, shveta malik <shveta(dot)malik(at)gmail(dot)com>
Subject: Re: Distinguish publication exclusions in object addresses
Date: 2026-09-18 04:18:26
Message-ID: CAJpy0uB-V44xSfAYfROwNzsqjJHO4u1OF0-LgoEUXP9w-p5OSQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Sep 18, 2026 at 8:20 AM Peter Smith <smithpb2250(at)gmail(dot)com> wrote:
>
> AFAICT, the patch has traded one kind of quoting problem for another.
>
> Before patch v3, the message might show nested quotes.
>
> After patch v3, the message might show mismatched quotes:
> CREATE PUBLICATION testpub9 FOR ALL TABLES EXCEPT (TABLE "schema has
> embedded "" quotes"."part has embedded "" quotes");
> ERROR: cannot specify relation "schema has embedded " quotes.part has
> embedded " quotes" in the publication EXCEPT clause
>
> ~
>
> PSA a v3 top-up patch to address the new problem.
>
> Of course, putting my escape_embedded_quotes() function where I did in
> the top-up doesn't seem appropriate. It would be better to associate
> that with the original RelationGetQualifiedRelationName() and call it
> from there, but RelationGetQualifiedRelationName was removed, so...
>

At first, I felt it was a problem in the entire code for base Postgres
and thus could be fixed separately. I tried to find queries on HEAD
where it already works and where it does not. Here are a few samples:

Problematic cases on HEAD:
1)
postgres=# SELECT '"schema has embedded "" quotes".nonexistent_table'::regclass;
ERROR: relation "schema has embedded " quotes.nonexistent_table" does not exist
LINE 1: SELECT '"schema has embedded "" quotes".nonexistent_table'::...
^
2)
postgres=# DROP TABLE "my""table";
ERROR: table "my"table" does not exist

The case where it is correctly quoted:

1)
postgres=# CREATE MATERIALIZED VIEW "schema has embedded ""
quotes"."my_mv" AS SELECT 1 AS id;
SELECT 1

postgres=# REFRESH MATERIALIZED VIEW CONCURRENTLY "schema has embedded
"" quotes"."my_mv";
ERROR: cannot refresh materialized view ""schema has embedded ""
quotes".my_mv" concurrently
HINT: Create a unique index with no WHERE clause on one or more
columns of the materialized view.

2)
postgres=# SELECT '"schema has embedded ""
quotes".nonexistent_func(int)'::regprocedure;
ERROR: function ""schema has embedded ""
quotes".nonexistent_func(int)" does not exist
LINE 1: SELECT '"schema has embedded "" quotes".nonexistent_func(int...

So, I don't have a strong opinion on whether we should fix it here or
separately. Fixing it here would be slightly better though.

But if we plan to fix it, it would be good to see how
RefreshMatViewByOid() handles it without using the new function (which
Peter has added).

I tried it:
+#if 0
relname = psprintf("%s.%s",
-
get_namespace_name(RelationGetNamespace(targetrel)),
-
RelationGetRelationName(targetrel));
+
escape_embedded_quotes(get_namespace_name(RelationGetNamespace(targetrel))),
+
escape_embedded_quotes(RelationGetRelationName(targetrel)));
errormsg = gettext_noop("cannot specify relation
\"%s\" in the publication EXCEPT clause");
+#endif
+ relname = quote_qualified_identifier(
+
get_namespace_name_or_temp(RelationGetNamespace(targetrel)),
+
RelationGetRelationName(targetrel));
+ errormsg = gettext_noop("cannot specify relation %s in
the publication EXCEPT clause");

After this I get correct output here:
postgres=# CREATE PUBLICATION testpub9 FOR ALL TABLES EXCEPT (TABLE
"schema has embedded "" quotes"."part has embedded "" quotes");
ERROR: cannot specify relation "schema has embedded "" quotes"."part
has embedded "" quotes" in the publication EXCEPT clause
DETAIL: This operation is not supported for individual partitions.

But for existing tests (added in main 001 patch), I get this:
postgres=# 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.

instead of:
ERROR: cannot specify relation "public.testpub Part2" in the
publication EXCEPT clause
DETAIL: This operation is not supported for individual partitions.

(Note: no quotes around public in new output.)

thanks
Shveta

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2026-09-18 04:26:36 Re: Distinguish publication exclusions in object addresses
Previous Message Haibo Yan 2026-09-18 04:14:45 Re: Global temporary tables