From 89aa97840f2b18caec5e8b7dbdefd1c9d36e5e1c Mon Sep 17 00:00:00 2001 From: "houzj.fnst" Date: Mon, 26 Sep 2022 16:32:33 +0800 Subject: [PATCH] Improve some error messages Improve some publication error messages that introduced in PG15. Also remove an unused queryString parameter from function CheckPubRelationColumnList(). --- src/backend/commands/publicationcmds.c | 26 ++++++++++++++------------ src/test/regress/expected/publication.out | 22 +++++++++++----------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/backend/commands/publicationcmds.c b/src/backend/commands/publicationcmds.c index 99011ee..ba1afc2 100644 --- a/src/backend/commands/publicationcmds.c +++ b/src/backend/commands/publicationcmds.c @@ -681,8 +681,8 @@ TransformPubWhereClauses(List *tables, const char *queryString, * Check the publication column lists expression for all relations in the list. */ static void -CheckPubRelationColumnList(List *tables, const char *queryString, - bool publish_schema, bool pubviaroot) +CheckPubRelationColumnList(List *tables, char *pubname, bool publish_schema, + bool pubviaroot) { ListCell *lc; @@ -706,10 +706,10 @@ CheckPubRelationColumnList(List *tables, const char *queryString, if (publish_schema) ereport(ERROR, errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("cannot use publication column list for relation \"%s.%s\"", + errmsg("cannot use column list for relation \"%s.%s\" in publication \"%s\"", get_namespace_name(RelationGetNamespace(pri->relation)), - RelationGetRelationName(pri->relation)), - errdetail("Column list cannot be specified if any schema is part of the publication or specified in the list.")); + RelationGetRelationName(pri->relation), pubname), + errdetail("Column lists cannot be specified in publications containing FOR TABLES IN SCHEMA elements.")); /* * If the publication doesn't publish changes via the root partitioned @@ -720,9 +720,10 @@ CheckPubRelationColumnList(List *tables, const char *queryString, pri->relation->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("cannot use publication column list for relation \"%s\"", - RelationGetRelationName(pri->relation)), - errdetail("Column list cannot be used for a partitioned table when %s is false.", + errmsg("cannot use column list for relation \"%s.%s\" in publication \"%s\"", + get_namespace_name(RelationGetNamespace(pri->relation)), + RelationGetRelationName(pri->relation), pubname), + errdetail("Column list cannot be specified for a partitioned table when %s is false.", "publish_via_partition_root"))); } } @@ -840,7 +841,7 @@ CreatePublication(ParseState *pstate, CreatePublicationStmt *stmt) TransformPubWhereClauses(rels, pstate->p_sourcetext, publish_via_partition_root); - CheckPubRelationColumnList(rels, pstate->p_sourcetext, + CheckPubRelationColumnList(rels, stmt->pubname, schemaidlist != NIL, publish_via_partition_root); @@ -1110,7 +1111,7 @@ AlterPublicationTables(AlterPublicationStmt *stmt, HeapTuple tup, publish_schema |= is_schema_publication(pubid); - CheckPubRelationColumnList(rels, queryString, publish_schema, + CheckPubRelationColumnList(rels, stmt->pubname, publish_schema, pubform->pubviaroot); PublicationAddTables(pubid, rels, false, stmt); @@ -1126,7 +1127,7 @@ AlterPublicationTables(AlterPublicationStmt *stmt, HeapTuple tup, TransformPubWhereClauses(rels, queryString, pubform->pubviaroot); - CheckPubRelationColumnList(rels, queryString, publish_schema, + CheckPubRelationColumnList(rels, stmt->pubname, publish_schema, pubform->pubviaroot); /* @@ -1299,7 +1300,8 @@ AlterPublicationSchemas(AlterPublicationStmt *stmt, if (!heap_attisnull(coltuple, Anum_pg_publication_rel_prattrs, NULL)) ereport(ERROR, errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("cannot add schema to the publication"), + errmsg("cannot add schema to publication \"%s\"", + stmt->pubname), errdetail("Schema cannot be added if any table that specifies column list is already part of the publication.")); ReleaseSysCache(coltuple); diff --git a/src/test/regress/expected/publication.out b/src/test/regress/expected/publication.out index bfce1e1..a0e3574 100644 --- a/src/test/regress/expected/publication.out +++ b/src/test/regress/expected/publication.out @@ -853,32 +853,32 @@ DETAIL: Column list used by the publication does not cover the replica identity SET client_min_messages = 'ERROR'; -- failure - cannot use column list and schema together CREATE PUBLICATION testpub_tbl9 FOR TABLES IN SCHEMA public, TABLE public.testpub_tbl7(a); -ERROR: cannot use publication column list for relation "public.testpub_tbl7" -DETAIL: Column list cannot be specified if any schema is part of the publication or specified in the list. +ERROR: cannot use column list for relation "public.testpub_tbl7" in publication "testpub_tbl9" +DETAIL: Column lists cannot be specified in publications containing FOR TABLES IN SCHEMA elements. -- ok - only publish schema CREATE PUBLICATION testpub_tbl9 FOR TABLES IN SCHEMA public; -- failure - add a table with column list when there is already a schema in the -- publication ALTER PUBLICATION testpub_tbl9 ADD TABLE public.testpub_tbl7(a); -ERROR: cannot use publication column list for relation "public.testpub_tbl7" -DETAIL: Column list cannot be specified if any schema is part of the publication or specified in the list. +ERROR: cannot use column list for relation "public.testpub_tbl7" in publication "testpub_tbl9" +DETAIL: Column lists cannot be specified in publications containing FOR TABLES IN SCHEMA elements. -- ok - only publish table with column list ALTER PUBLICATION testpub_tbl9 SET TABLE public.testpub_tbl7(a); -- failure - specify a schema when there is already a column list in the -- publication ALTER PUBLICATION testpub_tbl9 ADD TABLES IN SCHEMA public; -ERROR: cannot add schema to the publication +ERROR: cannot add schema to publication "testpub_tbl9" DETAIL: Schema cannot be added if any table that specifies column list is already part of the publication. -- failure - cannot SET column list and schema together ALTER PUBLICATION testpub_tbl9 SET TABLES IN SCHEMA public, TABLE public.testpub_tbl7(a); -ERROR: cannot use publication column list for relation "public.testpub_tbl7" -DETAIL: Column list cannot be specified if any schema is part of the publication or specified in the list. +ERROR: cannot use column list for relation "public.testpub_tbl7" in publication "testpub_tbl9" +DETAIL: Column lists cannot be specified in publications containing FOR TABLES IN SCHEMA elements. -- ok - drop table ALTER PUBLICATION testpub_tbl9 DROP TABLE public.testpub_tbl7; -- failure - cannot ADD column list and schema together ALTER PUBLICATION testpub_tbl9 ADD TABLES IN SCHEMA public, TABLE public.testpub_tbl7(a); -ERROR: cannot use publication column list for relation "public.testpub_tbl7" -DETAIL: Column list cannot be specified if any schema is part of the publication or specified in the list. +ERROR: cannot use column list for relation "public.testpub_tbl7" in publication "testpub_tbl9" +DETAIL: Column lists cannot be specified in publications containing FOR TABLES IN SCHEMA elements. RESET client_min_messages; DROP TABLE testpub_tbl5, testpub_tbl6, testpub_tbl7, testpub_tbl8, testpub_tbl8_1; DROP PUBLICATION testpub_table_ins, testpub_fortable, testpub_fortable_insert, testpub_col_list, testpub_tbl9; @@ -1009,8 +1009,8 @@ UPDATE rf_tbl_abcd_nopk SET a = 1; ALTER PUBLICATION testpub6 SET (PUBLISH_VIA_PARTITION_ROOT=0); -- fail - cannot use column list for partitioned table ALTER PUBLICATION testpub6 SET TABLE rf_tbl_abcd_part_pk (a); -ERROR: cannot use publication column list for relation "rf_tbl_abcd_part_pk" -DETAIL: Column list cannot be used for a partitioned table when publish_via_partition_root is false. +ERROR: cannot use column list for relation "public.rf_tbl_abcd_part_pk" in publication "testpub6" +DETAIL: Column list cannot be specified for a partitioned table when publish_via_partition_root is false. -- ok - can use column list for partition ALTER PUBLICATION testpub6 SET TABLE rf_tbl_abcd_part_pk_1 (a); -- ok - "a" is a PK col -- 2.7.2.windows.1