More improvements of error messages about mismatching relkind
authorPeter Eisentraut <peter@eisentraut.org>
Wed, 21 Jul 2021 05:40:05 +0000 (07:40 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Wed, 21 Jul 2021 05:52:10 +0000 (07:52 +0200)
Follow-up to 2ed532ee8c474e9767e76e1f3251cc3a0224358c, a few error
messages in the logical replication area currently only deal with
tables, but if we're anticipating more relkinds such as sequences
being handled, then these messages also fall into the category
affected by the previous patch, so adjust them too.

Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://www.postgresql.org/message-id/c9ba5c6a-4bd5-e12c-1b3c-edbcaedbf392@enterprisedb.com

src/backend/catalog/pg_publication.c
src/backend/executor/execReplication.c
src/test/regress/expected/publication.out

index 36bfff9706981e02812552cf732e91c78e6c381c..2a2fe03c13fe05c28123c71c86755760aa1ba048 100644 (file)
@@ -54,23 +54,23 @@ check_publication_add_relation(Relation targetrel)
        RelationGetForm(targetrel)->relkind != RELKIND_PARTITIONED_TABLE)
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-                errmsg("\"%s\" is not a table",
+                errmsg("cannot add relation \"%s\" to publication",
                        RelationGetRelationName(targetrel)),
-                errdetail("Only tables can be added to publications.")));
+                errdetail_relkind_not_supported(RelationGetForm(targetrel)->relkind)));
 
    /* Can't be system table */
    if (IsCatalogRelation(targetrel))
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-                errmsg("\"%s\" is a system table",
+                errmsg("cannot add relation \"%s\" to publication",
                        RelationGetRelationName(targetrel)),
-                errdetail("System tables cannot be added to publications.")));
+                errdetail("This operation is not supported for system tables.")));
 
    /* UNLOGGED and TEMP relations cannot be part of publication. */
    if (!RelationIsPermanent(targetrel))
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-                errmsg("table \"%s\" cannot be replicated",
+                errmsg("cannot add relation \"%s\" to publication",
                        RelationGetRelationName(targetrel)),
                 errdetail("Temporary and unlogged relations cannot be replicated.")));
 }
index 1e285e0349f46dea9387ed750879d7ecaff220f1..574d7d27fd92c9030649d847f7c6671895eff596 100644 (file)
@@ -608,22 +608,10 @@ void
 CheckSubscriptionRelkind(char relkind, const char *nspname,
                         const char *relname)
 {
-   /*
-    * Give a more specific error for foreign tables.
-    */
-   if (relkind == RELKIND_FOREIGN_TABLE)
-       ereport(ERROR,
-               (errcode(ERRCODE_WRONG_OBJECT_TYPE),
-                errmsg("cannot use relation \"%s.%s\" as logical replication target",
-                       nspname, relname),
-                errdetail("\"%s.%s\" is a foreign table.",
-                          nspname, relname)));
-
    if (relkind != RELKIND_RELATION && relkind != RELKIND_PARTITIONED_TABLE)
        ereport(ERROR,
                (errcode(ERRCODE_WRONG_OBJECT_TYPE),
                 errmsg("cannot use relation \"%s.%s\" as logical replication target",
                        nspname, relname),
-                errdetail("\"%s.%s\" is not a table.",
-                          nspname, relname)));
+                errdetail_relkind_not_supported(relkind)));
 }
index b5b065a1b6fc27588e60774d0fb868978d040823..4a5ef0bc24928a02a13ad81e4c30df92b3ffbc83 100644 (file)
@@ -160,8 +160,8 @@ DROP TABLE testpub_parted1;
 DROP PUBLICATION testpub_forparted, testpub_forparted1;
 -- fail - view
 CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_view;
-ERROR:  "testpub_view" is not a table
-DETAIL:  Only tables can be added to publications.
+ERROR:  cannot add relation "testpub_view" to publication
+DETAIL:  This operation is not supported for views.
 SET client_min_messages = 'ERROR';
 CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_tbl1, pub_test.testpub_nopk;
 RESET client_min_messages;
@@ -182,8 +182,8 @@ Tables:
 
 -- fail - view
 ALTER PUBLICATION testpub_default ADD TABLE testpub_view;
-ERROR:  "testpub_view" is not a table
-DETAIL:  Only tables can be added to publications.
+ERROR:  cannot add relation "testpub_view" to publication
+DETAIL:  This operation is not supported for views.
 ALTER PUBLICATION testpub_default ADD TABLE testpub_tbl1;
 ALTER PUBLICATION testpub_default SET TABLE testpub_tbl1;
 ALTER PUBLICATION testpub_default ADD TABLE pub_test.testpub_nopk;