>From 39bf631df574fdd7e5120541e7c3f8013227d1ef Mon Sep 17 00:00:00 2001 From: Manu Date: Tue, 22 Sep 2026 20:31:45 -0300 Subject: [PATCH] Add test coverage for the publication EXCEPT clause error paths check_publication_add_relation() has six ereport() paths that can report "cannot specify relation \"%s\" in the publication EXCEPT clause", but the regression tests only reach one of them, the one for individual partitions. Cover three more: a view, a system table and a temporary table. The temporary schema number depends on the backend, so that case prints the message with the number redacted, the way stats_ext.sql does. --- src/test/regress/expected/publication.out | 21 +++++++++++++++++++++ src/test/regress/sql/publication.sql | 18 ++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/test/regress/expected/publication.out b/src/test/regress/expected/publication.out index b55da39fde5..eae1c5ab335 100644 --- a/src/test/regress/expected/publication.out +++ b/src/test/regress/expected/publication.out @@ -1568,11 +1568,32 @@ DROP TABLE testpub_tbl4; CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_view; ERROR: cannot add relation "testpub_view" to publication DETAIL: This operation is not supported for views. +-- fail - view in the EXCEPT clause +CREATE PUBLICATION testpub_exceptview FOR ALL TABLES EXCEPT (TABLE testpub_view); +ERROR: cannot specify relation "public.testpub_view" in the publication EXCEPT clause +DETAIL: This operation is not supported for views. +-- fail - system table in the EXCEPT clause +CREATE PUBLICATION testpub_exceptsystbl FOR ALL TABLES EXCEPT (TABLE pg_class); +ERROR: cannot specify relation "pg_catalog.pg_class" in the publication EXCEPT clause +DETAIL: This operation is not supported for system tables. CREATE TEMPORARY TABLE testpub_temptbl(a int); -- fail - temporary table CREATE PUBLICATION testpub_fortemptbl FOR TABLE testpub_temptbl; ERROR: cannot add relation "testpub_temptbl" to publication DETAIL: This operation is not supported for temporary tables. +-- fail - temporary table in the EXCEPT clause. The temporary schema number +-- depends on the backend, so the message is printed with it redacted. +DO $$ +DECLARE + detail text; +BEGIN + CREATE PUBLICATION testpub_excepttemptbl FOR ALL TABLES EXCEPT (TABLE testpub_temptbl); +EXCEPTION WHEN invalid_parameter_value THEN + GET STACKED DIAGNOSTICS detail = PG_EXCEPTION_DETAIL; + RAISE NOTICE '% (%)', + regexp_replace(SQLERRM, 'pg_temp_[0-9]+', 'pg_temp_REDACTED'), detail; +END $$; +NOTICE: cannot specify relation "pg_temp_REDACTED.testpub_temptbl" in the publication EXCEPT clause (This operation is not supported for temporary tables.) DROP TABLE testpub_temptbl; CREATE UNLOGGED TABLE testpub_unloggedtbl(a int); -- fail - unlogged table diff --git a/src/test/regress/sql/publication.sql b/src/test/regress/sql/publication.sql index e3dbb2bc57c..dfd1aa83676 100644 --- a/src/test/regress/sql/publication.sql +++ b/src/test/regress/sql/publication.sql @@ -995,9 +995,27 @@ DROP TABLE testpub_tbl4; -- fail - view CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_view; +-- fail - view in the EXCEPT clause +CREATE PUBLICATION testpub_exceptview FOR ALL TABLES EXCEPT (TABLE testpub_view); + +-- fail - system table in the EXCEPT clause +CREATE PUBLICATION testpub_exceptsystbl FOR ALL TABLES EXCEPT (TABLE pg_class); + CREATE TEMPORARY TABLE testpub_temptbl(a int); -- fail - temporary table CREATE PUBLICATION testpub_fortemptbl FOR TABLE testpub_temptbl; +-- fail - temporary table in the EXCEPT clause. The temporary schema number +-- depends on the backend, so the message is printed with it redacted. +DO $$ +DECLARE + detail text; +BEGIN + CREATE PUBLICATION testpub_excepttemptbl FOR ALL TABLES EXCEPT (TABLE testpub_temptbl); +EXCEPTION WHEN invalid_parameter_value THEN + GET STACKED DIAGNOSTICS detail = PG_EXCEPTION_DETAIL; + RAISE NOTICE '% (%)', + regexp_replace(SQLERRM, 'pg_temp_[0-9]+', 'pg_temp_REDACTED'), detail; +END $$; DROP TABLE testpub_temptbl; CREATE UNLOGGED TABLE testpub_unloggedtbl(a int); -- 2.55.0