From 75da58afd4dfb1ad5ac8491198652d2678d25b90 Mon Sep 17 00:00:00 2001
From: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Date: Thu, 23 Apr 2026 13:36:09 +0530
Subject: [PATCH v4 1/2] Fix errmsg issues in ALTER TABLE SPLIT/MERGE PARTITION

Fix several issues with error messages in the ALTER TABLE SPLIT
PARTITION and ALTER TABLE MERGE PARTITIONS code:

1. In transformPartitionCmdForSplit(), the ereport() that fires when
   splitting a non-default partition while a default partition already
   exists had two errmsg() calls.  The second one is changed to
   errdetail(), with proper capitalization and trailing period.

2. All occurrences of 'can not' are replaced with 'cannot' for
   correctness across parse_utilcmd.c, partbounds.c, and tablecmds.c.

3. The grammatically incorrect 'DEFAULT partition should be one' is
   reworded to 'cannot specify more than one DEFAULT partition'.

4. Grammar fix in errhint: 'To split DEFAULT partition one of the new
   partition must be DEFAULT' -> 'To split a DEFAULT partition, one of
   the new partitions must be DEFAULT.'

5. Capitalize errdetail and add trailing period in
   check_two_partitions_bounds_range().
---
 src/backend/commands/tablecmds.c              |  2 +-
 src/backend/parser/parse_utilcmd.c            | 10 +++----
 src/backend/partitioning/partbounds.c         |  8 ++---
 src/test/regress/expected/partition_merge.out |  8 ++---
 src/test/regress/expected/partition_split.out | 29 ++++++++++---------
 5 files changed, 29 insertions(+), 28 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index eec09ba1ded..c7116bfedb4 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -23389,7 +23389,7 @@ SplitPartitionMoveRows(List **wqueue, Relation rel, Relation splitRel,
 			else
 				ereport(ERROR,
 						errcode(ERRCODE_CHECK_VIOLATION),
-						errmsg("can not find partition for split partition row"),
+						errmsg("cannot find partition for split partition row"),
 						errtable(splitRel));
 		}
 
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 37071502a9f..a7dd0b41bc2 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3618,7 +3618,7 @@ transformPartitionCmdForSplit(CreateStmtContext *cxt, PartitionCmd *partcmd)
 						if (default_index != -1)
 							ereport(ERROR,
 									errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-									errmsg("DEFAULT partition should be one"),
+									errmsg("cannot specify more than one DEFAULT partition"),
 									parser_errposition(cxt->pstate, sps->name->location));
 
 						default_index = foreach_current_index(sps);
@@ -3645,9 +3645,9 @@ transformPartitionCmdForSplit(CreateStmtContext *cxt, PartitionCmd *partcmd)
 	if (isSplitPartDefault && default_index == -1)
 		ereport(ERROR,
 				errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				errmsg("can not split DEFAULT partition \"%s\"",
+				errmsg("cannot split DEFAULT partition \"%s\"",
 					   get_rel_name(splitPartOid)),
-				errhint("To split DEFAULT partition one of the new partition must be DEFAULT."),
+				errhint("To split a DEFAULT partition, one of the new partitions must be DEFAULT."),
 				parser_errposition(cxt->pstate, ((SinglePartitionSpec *) linitial(splitlist))->name->location));
 
 	/*
@@ -3662,9 +3662,9 @@ transformPartitionCmdForSplit(CreateStmtContext *cxt, PartitionCmd *partcmd)
 
 		ereport(ERROR,
 				errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				errmsg("can not split non-DEFAULT partition \"%s\"",
+				errmsg("cannot split non-DEFAULT partition \"%s\"",
 					   get_rel_name(splitPartOid)),
-				errmsg("new partition cannot be DEFAULT because DEFAULT partition \"%s\" already exists",
+				errdetail("New partition cannot be DEFAULT because DEFAULT partition \"%s\" already exists.",
 					   get_rel_name(defaultPartOid)),
 				parser_errposition(cxt->pstate, spsDef->name->location));
 	}
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index 05250eda472..ed8166efa8a 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -5030,18 +5030,18 @@ check_two_partitions_bounds_range(Relation parent,
 		if (is_merge)
 			ereport(ERROR,
 					errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-					errmsg("can not merge partition \"%s\" together with partition \"%s\"",
+					errmsg("cannot merge partition \"%s\" together with partition \"%s\"",
 						   second_name->relname, first_name->relname),
-					errdetail("lower bound of partition \"%s\" is not equal to the upper bound of partition \"%s\"",
+					errdetail("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));
 		else
 			ereport(ERROR,
 					errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-					errmsg("can not split to partition \"%s\" together with partition \"%s\"",
+					errmsg("cannot split to partition \"%s\" together with partition \"%s\"",
 						   second_name->relname, first_name->relname),
-					errdetail("lower bound of partition \"%s\" is not equal to the upper bound of partition \"%s\"",
+					errdetail("Lower bound of partition \"%s\" is not equal to the upper bound of partition \"%s\".",
 							  second_name->relname, first_name->relname),
 					errhint("ALTER TABLE ... SPLIT PARTITION 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 883110e25d9..fc7a59982fa 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -34,15 +34,15 @@ HINT:  ALTER TABLE ... MERGE PARTITIONS can only merge partitions don't have sub
 -- DETAIL:  lower bound of partition "sales_mar2022" is not equal to the upper bound of 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:  can not merge partition "sales_mar2022" together with partition "sales_jan2022"
-DETAIL:  lower bound of partition "sales_mar2022" is not equal to the upper bound of partition "sales_jan2022"
+ERROR:  cannot merge partition "sales_mar2022" together with partition "sales_jan2022"
+DETAIL:  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:  can not merge partition "sales_jan2022" together with partition "sales_dec2021"
 -- DETAIL:  lower bound of partition "sales_jan2022" is not equal to the upper bound of 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:  can not merge partition "sales_jan2022" together with partition "sales_dec2021"
-DETAIL:  lower bound of partition "sales_jan2022" is not equal to the upper bound of partition "sales_dec2021"
+ERROR:  cannot merge partition "sales_jan2022" together with partition "sales_dec2021"
+DETAIL:  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;
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 43ca299648e..7a15c5b7130 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -106,10 +106,10 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO
   (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'),
    PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'));
-ERROR:  can not split to partition "sales_mar2022" together with partition "sales_feb2022"
+ERROR:  cannot split to partition "sales_mar2022" together with partition "sales_feb2022"
 LINE 3:    PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO...
                                                     ^
-DETAIL:  lower bound of partition "sales_mar2022" is not equal to the upper bound of partition "sales_feb2022"
+DETAIL:  Lower bound of partition "sales_mar2022" is not equal to the upper bound of partition "sales_feb2022".
 HINT:  ALTER TABLE ... SPLIT PARTITION requires the partition bounds to be adjacent.
 -- Tests for spaces between partitions, them should be executed without DEFAULT partition
 ALTER TABLE sales_range DETACH PARTITION sales_others;
@@ -467,10 +467,10 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_error FOR VALUES FROM ('2021-12-30') TO ('2022-02-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_others DEFAULT);
-ERROR:  can not split to partition "sales_error" together with partition "sales_dec2021"
+ERROR:  cannot split to partition "sales_error" together with partition "sales_dec2021"
 LINE 3:    PARTITION sales_error FOR VALUES FROM ('2021-12-30') TO (...
                                                   ^
-DETAIL:  lower bound of partition "sales_error" is not equal to the upper bound of partition "sales_dec2021"
+DETAIL:  Lower bound of partition "sales_error" is not equal to the upper bound of partition "sales_dec2021".
 HINT:  ALTER TABLE ... SPLIT PARTITION requires the partition bounds to be adjacent.
 -- sales_error intersects with sales_feb2022 (upper bound)
 -- ERROR:  can not split to partition "sales_feb2022" together with partition "sales_error"
@@ -479,10 +479,10 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_error FOR VALUES FROM ('2022-01-01') TO ('2022-02-02'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_others DEFAULT);
-ERROR:  can not split to partition "sales_feb2022" together with partition "sales_error"
+ERROR:  cannot split to partition "sales_feb2022" together with partition "sales_error"
 LINE 4:    PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO...
                                                     ^
-DETAIL:  lower bound of partition "sales_feb2022" is not equal to the upper bound of partition "sales_error"
+DETAIL:  Lower bound of partition "sales_feb2022" is not equal to the upper bound of partition "sales_error".
 HINT:  ALTER TABLE ... SPLIT PARTITION requires the partition bounds to be adjacent.
 -- sales_error intersects with sales_dec2021 (inside bound)
 -- ERROR:  can not split to partition "sales_error" together with partition "sales_dec2021"
@@ -491,10 +491,10 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_error FOR VALUES FROM ('2021-12-10') TO ('2021-12-20'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_others DEFAULT);
-ERROR:  can not split to partition "sales_error" together with partition "sales_dec2021"
+ERROR:  cannot split to partition "sales_error" together with partition "sales_dec2021"
 LINE 3:    PARTITION sales_error FOR VALUES FROM ('2021-12-10') TO (...
                                                   ^
-DETAIL:  lower bound of partition "sales_error" is not equal to the upper bound of partition "sales_dec2021"
+DETAIL:  Lower bound of partition "sales_error" is not equal to the upper bound of partition "sales_dec2021".
 HINT:  ALTER TABLE ... SPLIT PARTITION requires the partition bounds to be adjacent.
 -- sales_error intersects with sales_dec2021 (exactly the same bounds)
 -- ERROR:  can not split to partition "sales_error" together with partition "sales_dec2021"
@@ -503,10 +503,10 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
    PARTITION sales_error FOR VALUES FROM ('2021-12-01') TO ('2022-01-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'),
    PARTITION sales_others DEFAULT);
-ERROR:  can not split to partition "sales_error" together with partition "sales_dec2021"
+ERROR:  cannot split to partition "sales_error" together with partition "sales_dec2021"
 LINE 3:    PARTITION sales_error FOR VALUES FROM ('2021-12-01') TO (...
                                                   ^
-DETAIL:  lower bound of partition "sales_error" is not equal to the upper bound of partition "sales_dec2021"
+DETAIL:  Lower bound of partition "sales_error" is not equal to the upper bound of partition "sales_dec2021".
 HINT:  ALTER TABLE ... SPLIT PARTITION requires the partition bounds to be adjacent.
 -- ERROR:  can not split DEFAULT partition "sales_others"
 -- HINT:  To split DEFAULT partition one of the new partition must be DEFAULT.
@@ -514,10 +514,10 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2021 FOR VALUES FROM ('2021-12-01') TO ('2022-01-01'),
    PARTITION sales_jan2022 FOR VALUES FROM ('2022-01-01') TO ('2022-02-01'),
    PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'));
-ERROR:  can not split DEFAULT partition "sales_others"
+ERROR:  cannot split DEFAULT partition "sales_others"
 LINE 2:   (PARTITION sales_dec2021 FOR VALUES FROM ('2021-12-01') TO...
                      ^
-HINT:  To split DEFAULT partition one of the new partition must be DEFAULT.
+HINT:  To split a DEFAULT partition, one of the new partitions must be DEFAULT.
 -- no error: bounds of sales_noerror are between sales_dec2021 and sales_feb2022
 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
   (PARTITION sales_dec2021 FOR VALUES FROM ('2021-12-01') TO ('2022-01-01'),
@@ -895,9 +895,10 @@ ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
    PARTITION sales_east FOR VALUES IN ('Beijing', 'Delhi', 'Vladivostok'),
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'),
    PARTITION sales_others2 DEFAULT);
-ERROR:  new partition cannot be DEFAULT because DEFAULT partition "sales_others" already exists
+ERROR:  cannot split non-DEFAULT partition "sales_all"
 LINE 5:    PARTITION sales_others2 DEFAULT);
                      ^
+DETAIL:  New partition cannot be DEFAULT because DEFAULT partition "sales_others" already exists.
 DROP TABLE sales_list;
 -- Test for non-symbolic comparison of values (numeric values '0' and '0.0' are equal).
 CREATE TABLE t (a numeric) PARTITION BY LIST (a);
@@ -941,7 +942,7 @@ ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
    PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'),
    PARTITION sales_others DEFAULT,
    PARTITION sales_others2 DEFAULT);
-ERROR:  DEFAULT partition should be one
+ERROR:  cannot specify more than one DEFAULT partition
 LINE 6:    PARTITION sales_others2 DEFAULT);
                      ^
 DROP TABLE sales_list;
-- 
2.34.1

