Skip to content

Commit 81d5995

Browse files
committed
More improvements of error messages about mismatching relkind
Follow-up to 2ed532e, 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
1 parent 90b6c33 commit 81d5995

File tree

3 files changed

+10
-22
lines changed

3 files changed

+10
-22
lines changed

src/backend/catalog/pg_publication.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,23 @@ check_publication_add_relation(Relation targetrel)
5454
RelationGetForm(targetrel)->relkind != RELKIND_PARTITIONED_TABLE)
5555
ereport(ERROR,
5656
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
57-
errmsg("\"%s\" is not a table",
57+
errmsg("cannot add relation \"%s\" to publication",
5858
RelationGetRelationName(targetrel)),
59-
errdetail("Only tables can be added to publications.")));
59+
errdetail_relkind_not_supported(RelationGetForm(targetrel)->relkind)));
6060

6161
/* Can't be system table */
6262
if (IsCatalogRelation(targetrel))
6363
ereport(ERROR,
6464
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
65-
errmsg("\"%s\" is a system table",
65+
errmsg("cannot add relation \"%s\" to publication",
6666
RelationGetRelationName(targetrel)),
67-
errdetail("System tables cannot be added to publications.")));
67+
errdetail("This operation is not supported for system tables.")));
6868

6969
/* UNLOGGED and TEMP relations cannot be part of publication. */
7070
if (!RelationIsPermanent(targetrel))
7171
ereport(ERROR,
7272
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
73-
errmsg("table \"%s\" cannot be replicated",
73+
errmsg("cannot add relation \"%s\" to publication",
7474
RelationGetRelationName(targetrel)),
7575
errdetail("Temporary and unlogged relations cannot be replicated.")));
7676
}

src/backend/executor/execReplication.c

+1-13
Original file line numberDiff line numberDiff line change
@@ -608,22 +608,10 @@ void
608608
CheckSubscriptionRelkind(char relkind, const char *nspname,
609609
const char *relname)
610610
{
611-
/*
612-
* Give a more specific error for foreign tables.
613-
*/
614-
if (relkind == RELKIND_FOREIGN_TABLE)
615-
ereport(ERROR,
616-
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
617-
errmsg("cannot use relation \"%s.%s\" as logical replication target",
618-
nspname, relname),
619-
errdetail("\"%s.%s\" is a foreign table.",
620-
nspname, relname)));
621-
622611
if (relkind != RELKIND_RELATION && relkind != RELKIND_PARTITIONED_TABLE)
623612
ereport(ERROR,
624613
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
625614
errmsg("cannot use relation \"%s.%s\" as logical replication target",
626615
nspname, relname),
627-
errdetail("\"%s.%s\" is not a table.",
628-
nspname, relname)));
616+
errdetail_relkind_not_supported(relkind)));
629617
}

src/test/regress/expected/publication.out

+4-4
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ DROP TABLE testpub_parted1;
160160
DROP PUBLICATION testpub_forparted, testpub_forparted1;
161161
-- fail - view
162162
CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_view;
163-
ERROR: "testpub_view" is not a table
164-
DETAIL: Only tables can be added to publications.
163+
ERROR: cannot add relation "testpub_view" to publication
164+
DETAIL: This operation is not supported for views.
165165
SET client_min_messages = 'ERROR';
166166
CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_tbl1, pub_test.testpub_nopk;
167167
RESET client_min_messages;
@@ -182,8 +182,8 @@ Tables:
182182

183183
-- fail - view
184184
ALTER PUBLICATION testpub_default ADD TABLE testpub_view;
185-
ERROR: "testpub_view" is not a table
186-
DETAIL: Only tables can be added to publications.
185+
ERROR: cannot add relation "testpub_view" to publication
186+
DETAIL: This operation is not supported for views.
187187
ALTER PUBLICATION testpub_default ADD TABLE testpub_tbl1;
188188
ALTER PUBLICATION testpub_default SET TABLE testpub_tbl1;
189189
ALTER PUBLICATION testpub_default ADD TABLE pub_test.testpub_nopk;

0 commit comments

Comments
 (0)