diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c index a09beec34d8..73dea0375be 100644 --- a/src/backend/partitioning/partbounds.c +++ b/src/backend/partitioning/partbounds.c @@ -5419,7 +5419,8 @@ check_partition_bounds_for_split_range(Relation parent, "ALTER TABLE ... SPLIT PARTITION"), parser_errposition(pstate, exprLocation((Node *) datum))); } - else + + if (last) { PartitionRangeBound *split_upper; diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out index 961b37953c8..a2ccbe5138b 100644 --- a/src/test/regress/expected/partition_split.out +++ b/src/test/regress/expected/partition_split.out @@ -1188,6 +1188,22 @@ SELECT tableoid::regclass, * FROM sales_range ORDER BY tableoid::regclass::text DROP TABLE sales_range; -- +-- Test that the explicit partition bound cannot extend outside the split +-- partition's bound when a DEFAULT partition is specified. +-- +CREATE TABLE t (i int) PARTITION BY RANGE (i); +CREATE TABLE tp_0_51 PARTITION OF t FOR VALUES FROM (0) TO (51); +CREATE TABLE tp_51_100 PARTITION OF t FOR VALUES FROM (51) TO (100); +-- ERROR +ALTER TABLE t SPLIT PARTITION tp_0_51 INTO + (PARTITION tp_0_51 FOR VALUES FROM (0) TO (53), + PARTITION tp_default DEFAULT); +ERROR: upper bound of partition "tp_0_51" is greater than upper bound of split partition "tp_0_51" +LINE 2: (PARTITION tp_0_51 FOR VALUES FROM (0) TO (53), + ^ +HINT: ALTER TABLE ... SPLIT PARTITION require combined bounds of new partitions must exactly match the bound of the split partition. +DROP TABLE t; +-- -- Try to SPLIT partition of another table. -- CREATE TABLE t1(i int, t text) PARTITION BY LIST (t); diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql index a110fc87867..d9821c5e2a3 100644 --- a/src/test/regress/sql/partition_split.sql +++ b/src/test/regress/sql/partition_split.sql @@ -834,6 +834,21 @@ SELECT tableoid::regclass, * FROM sales_range ORDER BY tableoid::regclass::text DROP TABLE sales_range; +-- +-- Test that the explicit partition bound cannot extend outside the split +-- partition's bound when a DEFAULT partition is specified. +-- +CREATE TABLE t (i int) PARTITION BY RANGE (i); +CREATE TABLE tp_0_51 PARTITION OF t FOR VALUES FROM (0) TO (51); +CREATE TABLE tp_51_100 PARTITION OF t FOR VALUES FROM (51) TO (100); + +-- ERROR +ALTER TABLE t SPLIT PARTITION tp_0_51 INTO + (PARTITION tp_0_51 FOR VALUES FROM (0) TO (53), + PARTITION tp_default DEFAULT); + +DROP TABLE t; + -- -- Try to SPLIT partition of another table. --