pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: wrong relkind error messages
Date: Tue, 20 Jul 2021 17:08:53 +0200
Message-ID: <c9ba5c6a-4bd5-e12c-1b3c-edbcaedbf392@enterprisedb.com> (raw)
In-Reply-To: <08b1063f-5341-c30e-6789-b523dd0e9e29@enterprisedb.com>
References: <202107021610.fv2n3ehw4yu7@alvherre.pgsql>
	<08b1063f-5341-c30e-6789-b523dd0e9e29@enterprisedb.com>


While reviewing the logical decoding of sequences patch, I found a few 
more places that could be updated in the new style introduced by this 
thread.  See attached patch.
From 92a06ebfa6f856246c2642a4e45c5b2af69a911d Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Tue, 20 Jul 2021 16:28:44 +0200
Subject: [PATCH] More improvements of error messages about mismatching relkind

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.
---
 src/backend/catalog/pg_publication.c      | 10 +++++-----
 src/backend/executor/execReplication.c    | 14 +-------------
 src/test/regress/expected/publication.out |  8 ++++----
 3 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c
index 36bfff9706..2a2fe03c13 100644
--- a/src/backend/catalog/pg_publication.c
+++ b/src/backend/catalog/pg_publication.c
@@ -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.")));
 }
diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c
index 1e285e0349..574d7d27fd 100644
--- a/src/backend/executor/execReplication.c
+++ b/src/backend/executor/execReplication.c
@@ -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)));
 }
diff --git a/src/test/regress/expected/publication.out b/src/test/regress/expected/publication.out
index b5b065a1b6..4a5ef0bc24 100644
--- a/src/test/regress/expected/publication.out
+++ b/src/test/regress/expected/publication.out
@@ -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;
-- 
2.32.0



Attachments:

0001-More-improvements-of-error-messages-about-mismatchin.patch (text/plain, 4.5K) download From 92a06ebfa6f856246c2642a4e45c5b2af69a911d Mon Sep 17 00:00:00 2001 From: Peter Eisentraut <peter@eisentraut.org> Date: Tue, 20 Jul 2021 16:28:44 +0200 Subject: [PATCH] More improvements of error messages about mismatching relkind 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. --- src/backend/catalog/pg_publication.c | 10 +++++----- src/backend/executor/execReplication.c | 14 +------------- src/test/regress/expected/publication.out | 8 ++++---- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index 36bfff9706..2a2fe03c13 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -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."))); } diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c index 1e285e0349..574d7d27fd 100644 --- a/src/backend/executor/execReplication.c +++ b/src/backend/executor/execReplication.c @@ -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))); } diff --git a/src/test/regress/expected/publication.out b/src/test/regress/expected/publication.out index b5b065a1b6..4a5ef0bc24 100644 --- a/src/test/regress/expected/publication.out +++ b/src/test/regress/expected/publication.out @@ -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; -- 2.32.0

view thread (20+ messages)  latest in thread

Message-ID: <c9ba5c6a-4bd5-e12c-1b3c-edbcaedbf392@enterprisedb.com>
Permalink:  ../c9ba5c6a-4bd5-e12c-1b3c-edbcaedbf392@enterprisedb.com/
Also on:    postgresql.org/message-id/c9ba5c6a-4bd5-e12c-1b3c-edbcaedbf392@enterprisedb.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: peter.eisentraut@enterprisedb.com
  Subject: Re: wrong relkind error messages
  In-Reply-To: <c9ba5c6a-4bd5-e12c-1b3c-edbcaedbf392@enterprisedb.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox