From b73cc0afd61b588a17528f59901334c1839fc33e Mon Sep 17 00:00:00 2001 From: jian he Date: Mon, 16 Jun 2025 11:54:41 +0800 Subject: [PATCH v45 2/2] error message refactoring --- src/backend/parser/parse_utilcmd.c | 20 ++++++++----------- src/backend/partitioning/partbounds.c | 3 ++- src/test/regress/expected/partition_merge.out | 18 ++++++++++++----- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index eb8a937e1e8..4fe9cd33328 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -3493,7 +3493,7 @@ transformRuleStmt(RuleStmt *stmt, const char *queryString, /* * checkPartition - * Check that partRelOid is an oid of partition of the parent table rel + * Check whether partRelOid is a leaf partition of the parent table (rel). */ static void checkPartition(Relation rel, Oid partRelOid) @@ -3505,26 +3505,22 @@ checkPartition(Relation rel, Oid partRelOid) if (partRel->rd_rel->relkind != RELKIND_RELATION) ereport(ERROR, errcode(ERRCODE_WRONG_OBJECT_TYPE), - errmsg("\"%s\" is not a table", - RelationGetRelationName(partRel))); + errmsg("\"%s\" is not a table", RelationGetRelationName(partRel)), + errhint("ALTER TABLE ... MERGE PARTITIONS can only merge partitions don't have sub-partitions")); if (!partRel->rd_rel->relispartition) ereport(ERROR, errcode(ERRCODE_WRONG_OBJECT_TYPE), - errmsg("\"%s\" is not a partition", - RelationGetRelationName(partRel))); + errmsg("\"%s\" is not a partition of partitioned table \"%s\"", + RelationGetRelationName(partRel), RelationGetRelationName(rel)), + errhint("ALTER TABLE ... MERGE PARTITIONS can only merge partitions don't have sub-partitions")); if (get_partition_parent(partRelOid, false) != RelationGetRelid(rel)) ereport(ERROR, errcode(ERRCODE_UNDEFINED_TABLE), errmsg("relation \"%s\" is not a partition of relation \"%s\"", - RelationGetRelationName(partRel), - RelationGetRelationName(rel))); - - /* Permissions checks */ - if (!object_ownercheck(RelationRelationId, RelationGetRelid(partRel), GetUserId())) - aclcheck_error(ACLCHECK_NOT_OWNER, get_relkind_objtype(partRel->rd_rel->relkind), - RelationGetRelationName(partRel)); + RelationGetRelationName(partRel), RelationGetRelationName(rel)), + errhint("ALTER TABLE ... MERGE PARTITIONS can only merge partitions don't have sub-partitions")); table_close(partRel, NoLock); } diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c index 2664c7b7091..9f7c01b7fa8 100644 --- a/src/backend/partitioning/partbounds.c +++ b/src/backend/partitioning/partbounds.c @@ -5028,8 +5028,9 @@ check_two_partitions_bounds_range(Relation parent, ereport(ERROR, errcode(ERRCODE_INVALID_OBJECT_DEFINITION), - errmsg("lower bound of partition \"%s\" conflicts with upper bound of previous partition \"%s\"", + errmsg("lower bound of partition \"%s\" is not equal to the upper bound of partition \"%s\"", second_name->relname, first_name->relname), + errhint("ALTER TABLE ... MERGE PARTITIONS requires the partition bounds to be adjacent."), parser_errposition(pstate, datum->location)); } } diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out index 4bfc4f7b5ff..20fa6c13680 100644 --- a/src/test/regress/expected/partition_merge.out +++ b/src/test/regress/expected/partition_merge.out @@ -29,14 +29,17 @@ LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2... -- ERROR: "sales_apr2022" is not a table ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022; ERROR: "sales_apr2022" is not a table +HINT: ALTER TABLE ... MERGE PARTITIONS can only merge partitions don't have sub-partitions -- ERROR: lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022" -- (space between sections sales_jan2022 and sales_mar2022) ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022; -ERROR: lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022" +ERROR: lower bound of partition "sales_mar2022" is not equal to the upper bound of partition "sales_jan2022" +HINT: ALTER TABLE ... MERGE PARTITIONS requires the partition bounds to be adjacent. -- ERROR: lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021" -- (space between sections sales_dec2021 and sales_jan2022) ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022; -ERROR: lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021" +ERROR: lower bound of partition "sales_jan2022" is not equal to the upper bound of partition "sales_dec2021" +HINT: ALTER TABLE ... MERGE PARTITIONS requires the partition bounds to be adjacent. -- ERROR: partition with name "sales_feb2022" is already used ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, partitions_merge_schema.sales_feb2022) INTO sales_feb_mar_apr2022; ERROR: partition with name "sales_feb2022" is already used @@ -611,13 +614,16 @@ CREATE TABLE sales_external (LIKE sales_list); CREATE TABLE sales_external2 (vch VARCHAR(5)); -- ERROR: "sales_external" is not a partition ALTER TABLE sales_list MERGE PARTITIONS (sales_west, sales_east, sales_external) INTO sales_all; -ERROR: "sales_external" is not a partition +ERROR: "sales_external" is not a partition of partitioned table "sales_list" +HINT: ALTER TABLE ... MERGE PARTITIONS can only merge partitions don't have sub-partitions -- ERROR: "sales_external2" is not a partition ALTER TABLE sales_list MERGE PARTITIONS (sales_west, sales_east, sales_external2) INTO sales_all; -ERROR: "sales_external2" is not a partition +ERROR: "sales_external2" is not a partition of partitioned table "sales_list" +HINT: ALTER TABLE ... MERGE PARTITIONS can only merge partitions don't have sub-partitions -- ERROR: relation "sales_nord2" is not a partition of relation "sales_list" ALTER TABLE sales_list MERGE PARTITIONS (sales_west, sales_nord2, sales_east) INTO sales_all; ERROR: relation "sales_nord2" is not a partition of relation "sales_list" +HINT: ALTER TABLE ... MERGE PARTITIONS can only merge partitions don't have sub-partitions DROP TABLE sales_external2; DROP TABLE sales_external; DROP TABLE sales_list2; @@ -759,9 +765,11 @@ CREATE TABLE t3 (i int, t text); -- ERROR: relation "t1p1" is not a partition of relation "t2" ALTER TABLE t2 MERGE PARTITIONS (t1p1, t2pa) INTO t2p; ERROR: relation "t1p1" is not a partition of relation "t2" +HINT: ALTER TABLE ... MERGE PARTITIONS can only merge partitions don't have sub-partitions -- ERROR: "t3" is not a partition ALTER TABLE t2 MERGE PARTITIONS (t2pa, t3) INTO t2p; -ERROR: "t3" is not a partition +ERROR: "t3" is not a partition of partitioned table "t2" +HINT: ALTER TABLE ... MERGE PARTITIONS can only merge partitions don't have sub-partitions DROP TABLE t3; DROP TABLE t2; DROP TABLE t1; -- 2.34.1