On Tue, May 5, 2026 at 3:57 PM Ayush Tiwari <[email protected]> wrote:
> v6 attached, addressing the remaining point.
I've pushed these with some changes:
Additional corrections:
"can only merge partitions don't have sub-partitions"
-> "that don't...".
"new partition \"%s\" cannot have this value because split partition
\"%s\" does not have"
-> "does not have it"
ERROR: cannot split DEFAULT partition "sales_others"
LINE 2: (PARTITION sales_dec2021 FOR VALUES FROM ('2021-12-01') TO...
^
HINT: To split a DEFAULT partition, one of the new partitions must be DEFAULT.
-> The caret above was pointing to a seemingly-random non-default partition.
"new partitions combined partition bounds..."
-> needed an apostrophe
> In 0001,
> check_two_partitions_bounds_range() no longer takes an is_merge
> argument. The merge call site passes InvalidOid, the split call site
> passes splitPartOid, and the helper derives a local is_merge value from
> that. I used OidIsValid(splitPartOid) rather than a NULL comparison,
> since splitPartOid is an Oid.
In the end, I decided to split this part out into the attached, and
have not committed it since the original wasn't really in error, just
sounded a bit off. I also found a couple other places that could use
wordsmithing as well, but it's not as clear-cut:
ERROR: new partition "sales_west" cannot have this value because
split partition "sales_all" does not have
LINE 2: ...st FOR VALUES IN ('Lisbon', 'New York', 'Madrid', 'Melbourne...
^
-> It seems weird to have "this value" in the errmsg. Sure, the caret
points to the right place, but the message seems better to state "new
partition X contains a value not found in split partition Y". Other
places in the split/merge code do quote values in messages, so maybe
we can here as well? Not sure if it matters much.
"new partition \"%s\" would overlap with another (not split) partition \"%s\"
-> "another (not split)" might be better as "an existing", but I'm
open to other opinions.
--
John Naylor
Amazon Web Services
From d5e70837fb911284daa6108106c1a108c6063dda Mon Sep 17 00:00:00 2001
From: John Naylor <[email protected]>
Date: Thu, 7 May 2026 18:48:43 +0700
Subject: [PATCH v7] Message improvements
---
src/backend/partitioning/partbounds.c | 20 +++++++++----------
src/test/regress/expected/partition_merge.out | 4 ++--
src/test/regress/expected/partition_split.out | 20 +++++++++----------
3 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index 9b4277a4987..061154c634f 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -4990,8 +4990,8 @@ satisfies_hash_partition(PG_FUNCTION_ARGS)
* second_name: name of the second partition
* second_bound: bound of the second partition
* defaultPart: true if one of the new partitions is DEFAULT
- * is_merge: true indicates the operation is MERGE PARTITIONS;
- * false indicates the operation is SPLIT PARTITION.
+ * splitPartOid: OID of the partition being split, or InvalidOid for
+ * MERGE PARTITIONS
* pstate: pointer to ParseState struct for determining error position
*/
static void
@@ -5001,7 +5001,7 @@ check_two_partitions_bounds_range(Relation parent,
RangeVar *second_name,
PartitionBoundSpec *second_bound,
bool defaultPart,
- bool is_merge,
+ Oid splitPartOid,
ParseState *pstate)
{
PartitionKey key = RelationGetPartitionKey(parent);
@@ -5027,23 +5027,23 @@ check_two_partitions_bounds_range(Relation parent,
{
PartitionRangeDatum *datum = linitial(second_bound->lowerdatums);
- if (is_merge)
+ if (!OidIsValid(splitPartOid))
ereport(ERROR,
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("cannot merge partition \"%s\" together with partition \"%s\"",
second_name->relname, first_name->relname),
errdetail("The 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."),
+ errhint("ALTER TABLE ... MERGE PARTITIONS requires the old partition bounds to be adjacent."),
parser_errposition(pstate, datum->location));
else
ereport(ERROR,
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
- errmsg("cannot split to partition \"%s\" together with partition \"%s\"",
- second_name->relname, first_name->relname),
+ errmsg("cannot split partition \"%s\"",
+ get_rel_name(splitPartOid)),
errdetail("The 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."),
+ errhint("ALTER TABLE ... SPLIT PARTITION requires the new partition bounds to be adjacent."),
parser_errposition(pstate, datum->location));
}
}
@@ -5147,7 +5147,7 @@ calculate_partition_bound_for_merge(Relation parent,
(RangeVar *) list_nth(partNames, index),
(PartitionBoundSpec *) list_nth(bounds, index),
false,
- true,
+ InvalidOid,
pstate);
}
@@ -5850,7 +5850,7 @@ check_partitions_for_split(Relation parent,
check_two_partitions_bounds_range(parent, spsPrev->name, spsPrev->bound,
sps->name, sps->bound,
createDefaultPart,
- false,
+ splitPartOid,
pstate);
spsPrev = sps;
diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out
index d3818f1bf9b..807a90ba366 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -35,13 +35,13 @@ HINT: ALTER TABLE ... MERGE PARTITIONS can only merge partitions that don't hav
ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022;
ERROR: cannot merge partition "sales_mar2022" together with partition "sales_jan2022"
DETAIL: The 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.
+HINT: ALTER TABLE ... MERGE PARTITIONS requires the old partition bounds to be adjacent.
-- ERROR
-- (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: cannot merge partition "sales_jan2022" together with partition "sales_dec2021"
DETAIL: The 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.
+HINT: ALTER TABLE ... MERGE PARTITIONS requires the old partition bounds to be adjacent.
-- ERROR
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
diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out
index 961b37953c8..081f948ebda 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -103,11 +103,11 @@ 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: cannot split to partition "sales_mar2022" together with partition "sales_feb2022"
+ERROR: cannot split partition "sales_feb_mar_apr2022"
LINE 3: PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO...
^
DETAIL: The 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.
+HINT: ALTER TABLE ... SPLIT PARTITION requires the new 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;
-- ERROR
@@ -462,11 +462,11 @@ 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: cannot split to partition "sales_error" together with partition "sales_dec2021"
+ERROR: cannot split partition "sales_others"
LINE 3: PARTITION sales_error FOR VALUES FROM ('2021-12-30') TO (...
^
DETAIL: The 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.
+HINT: ALTER TABLE ... SPLIT PARTITION requires the new partition bounds to be adjacent.
-- sales_error intersects with sales_feb2022 (upper bound)
-- ERROR
ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
@@ -474,11 +474,11 @@ 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: cannot split to partition "sales_feb2022" together with partition "sales_error"
+ERROR: cannot split partition "sales_others"
LINE 4: PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO...
^
DETAIL: The 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.
+HINT: ALTER TABLE ... SPLIT PARTITION requires the new partition bounds to be adjacent.
-- sales_error intersects with sales_dec2021 (inside bound)
-- ERROR
ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
@@ -486,11 +486,11 @@ 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: cannot split to partition "sales_error" together with partition "sales_dec2021"
+ERROR: cannot split partition "sales_others"
LINE 3: PARTITION sales_error FOR VALUES FROM ('2021-12-10') TO (...
^
DETAIL: The 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.
+HINT: ALTER TABLE ... SPLIT PARTITION requires the new partition bounds to be adjacent.
-- sales_error intersects with sales_dec2021 (exactly the same bounds)
-- ERROR
ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
@@ -498,11 +498,11 @@ 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: cannot split to partition "sales_error" together with partition "sales_dec2021"
+ERROR: cannot split partition "sales_others"
LINE 3: PARTITION sales_error FOR VALUES FROM ('2021-12-01') TO (...
^
DETAIL: The 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.
+HINT: ALTER TABLE ... SPLIT PARTITION requires the new partition bounds to be adjacent.
-- ERROR
ALTER TABLE sales_range SPLIT PARTITION sales_others INTO
(PARTITION sales_dec2021 FOR VALUES FROM ('2021-12-01') TO ('2022-01-01'),
--
2.54.0