From fc56f5b787bc74e146a647a5e4efaf0f70162cfd Mon Sep 17 00:00:00 2001 From: Ayush Tiwari Date: Wed, 22 Apr 2026 13:59:12 +0530 Subject: [PATCH v3] 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. The confusing messages 'can not split to partition X together with partition Y' and 'can not merge partition X together with partition Y' are rewritten as 'cannot split/merge non-adjacent partitions X and Y' with a clearer errdetail. The now-redundant errhint about adjacency is removed. 5. 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.' 6. Replace exact-copy '-- ERROR: ...' comment lines in partition_split.sql, partition_merge.sql, and their .out files with short '-- ERROR' markers to reduce maintenance burden while keeping visual error indicators. --- src/backend/commands/tablecmds.c | 2 +- src/backend/parser/parse_utilcmd.c | 10 +- src/backend/partitioning/partbounds.c | 10 +- src/test/regress/expected/partition_merge.out | 52 ++++---- src/test/regress/expected/partition_split.out | 112 ++++++++---------- src/test/regress/sql/partition_merge.sql | 42 ++++--- src/test/regress/sql/partition_split.sql | 78 ++++++------ 7 files changed, 139 insertions(+), 167 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..438e255939e 100644 --- a/src/backend/partitioning/partbounds.c +++ b/src/backend/partitioning/partbounds.c @@ -5030,20 +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 non-adjacent partitions \"%s\" and \"%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 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 non-adjacent partitions \"%s\" and \"%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 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..d10fd75844c 100644 --- a/src/test/regress/expected/partition_merge.out +++ b/src/test/regress/expected/partition_merge.out @@ -21,30 +21,26 @@ CREATE TABLE sales_apr_1 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01 CREATE TABLE sales_apr_2 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-15') TO ('2022-05-01'); ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'); CREATE TABLE sales_others PARTITION OF sales_range DEFAULT; --- ERROR: partition with name "sales_feb2022" is already used +-- ERROR ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022; ERROR: partition with name "sales_feb2022" is already used LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2... ^ --- ERROR: "sales_apr2022" is not a table +-- ERROR 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: 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 -- (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" -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" +ERROR: cannot merge non-adjacent partitions "sales_mar2022" and "sales_jan2022" +DETAIL: Lower bound of partition "sales_mar2022" is not equal to upper bound of partition "sales_jan2022". +-- 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: 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" -HINT: ALTER TABLE ... MERGE PARTITIONS requires the partition bounds to be adjacent. --- ERROR: partition with name "sales_feb2022" is already used +ERROR: cannot merge non-adjacent partitions "sales_jan2022" and "sales_dec2021" +DETAIL: Lower bound of partition "sales_jan2022" is not equal to upper bound of partition "sales_dec2021". +-- 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 LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, partitions... @@ -480,15 +476,15 @@ CREATE TABLE sales_nord2 PARTITION OF sales_list2 FOR VALUES IN ('Oslo', 'St. Pe CREATE TABLE sales_others2 PARTITION OF sales_list2 DEFAULT; CREATE TABLE sales_external (LIKE sales_list); CREATE TABLE sales_external2 (vch VARCHAR(5)); --- ERROR: "sales_external" is not a partition of partitioned table "sales_list" +-- ERROR ALTER TABLE sales_list MERGE PARTITIONS (sales_west, sales_east, sales_external) INTO sales_all; 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 of partitioned table "sales_list" +-- ERROR ALTER TABLE sales_list MERGE PARTITIONS (sales_west, sales_east, sales_external2) INTO sales_all; 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" +-- ERROR 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. @@ -630,11 +626,11 @@ CREATE TABLE t1p1 PARTITION OF t1 FOR VALUES FROM (1, 1) TO (1, 2); CREATE TABLE t2 (i int, t text) PARTITION BY RANGE (t); CREATE TABLE t2pa PARTITION OF t2 FOR VALUES FROM ('A') TO ('C'); CREATE TABLE t3 (i int, t text); --- ERROR: relation "t1p1" is not a partition of relation "t2" +-- ERROR 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 of partitioned table "t2" +-- ERROR ALTER TABLE t2 MERGE PARTITIONS (t2pa, t3) INTO t2p; ERROR: "t3" is not a partition of partitioned table "t2" HINT: ALTER TABLE ... MERGE PARTITIONS can only merge partitions don't have sub-partitions. @@ -690,7 +686,7 @@ EXECUTE get_partition_info('{t}'); tp_3_4 | t | r | f | FOR VALUES FROM (3) TO (4) (2 rows) --- ERROR: cannot create a permanent relation as partition of temporary relation "t" +-- ERROR ALTER TABLE t MERGE PARTITIONS (tp_0_3, tp_3_4) INTO tp_0_4; ERROR: cannot create a permanent relation as partition of temporary relation "t" ROLLBACK; @@ -806,19 +802,19 @@ CREATE TABLE t (i int) PARTITION BY RANGE (i); CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1); CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2); SET SESSION AUTHORIZATION regress_partition_merge_bob; --- ERROR: must be owner of table t +-- ERROR ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2; ERROR: must be owner of table t RESET SESSION AUTHORIZATION; ALTER TABLE t OWNER TO regress_partition_merge_bob; SET SESSION AUTHORIZATION regress_partition_merge_bob; --- ERROR: must be owner of table tp_0_1 +-- ERROR ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2; ERROR: must be owner of table tp_0_1 RESET SESSION AUTHORIZATION; ALTER TABLE tp_0_1 OWNER TO regress_partition_merge_bob; SET SESSION AUTHORIZATION regress_partition_merge_bob; --- ERROR: must be owner of table tp_1_2 +-- ERROR ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2; ERROR: must be owner of table tp_1_2 RESET SESSION AUTHORIZATION; @@ -852,7 +848,7 @@ ALTER TABLE t ATTACH PARTITION tp_1_2 FOR VALUES FROM (1) TO (2); partitions_merge_schema | tp_1_2 | table | regress_partition_merge_bob (1 row) --- ERROR: partitions being merged have different owners +-- ERROR ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2; ERROR: partitions being merged have different owners DROP TABLE t; @@ -864,10 +860,10 @@ DROP ROLE regress_partition_merge_bob; CREATE TABLE t (i int) PARTITION BY HASH(i); CREATE TABLE tp1 PARTITION OF t FOR VALUES WITH (MODULUS 2, REMAINDER 0); CREATE TABLE tp2 PARTITION OF t FOR VALUES WITH (MODULUS 2, REMAINDER 1); --- ERROR: partition of hash-partitioned table cannot be merged +-- ERROR ALTER TABLE t MERGE PARTITIONS (tp1, tp2) INTO tp3; ERROR: partition of hash-partitioned table cannot be merged --- ERROR: list of partitions to be merged should include at least two partitions +-- ERROR ALTER TABLE t MERGE PARTITIONS (tp1) INTO tp3; ERROR: list of partitions to be merged should include at least two partitions DROP TABLE t; @@ -999,7 +995,7 @@ Indexes: Referenced by: TABLE "t_fk" CONSTRAINT "t_fk_i_fkey" FOREIGN KEY (i) REFERENCES t(i) NOT VALID --- ERROR: insert or update on table "t_fk" violates foreign key constraint "t_fk_i_fkey" +-- ERROR ALTER TABLE t_fk VALIDATE CONSTRAINT t_fk_i_fkey; ERROR: insert or update on table "t_fk" violates foreign key constraint "t_fk_i_fkey" DETAIL: Key (i)=(2) is not present in table "t". @@ -1026,7 +1022,7 @@ Indexes: Referenced by: TABLE "t_fk" CONSTRAINT "t_fk_i_fkey" FOREIGN KEY (i) REFERENCES t(i) NOT ENFORCED --- ERROR: insert or update on table "t_fk" violates foreign key constraint "t_fk_i_fkey" +-- ERROR ALTER TABLE t_fk ALTER CONSTRAINT t_fk_i_fkey ENFORCED; ERROR: insert or update on table "t_fk" violates foreign key constraint "t_fk_i_fkey" DETAIL: Key (i)=(2) is not present in table "t". @@ -1070,7 +1066,7 @@ ALTER TABLE t ADD CHECK (i > 0); INSERT INTO t VALUES (5), (15); ALTER TABLE t MERGE PARTITIONS (tp_1, tp_2) INTO tp_12; INSERT INTO t VALUES (16); --- ERROR: new row for relation "tp_12" violates check constraint "t_i_check" +-- ERROR INSERT INTO t VALUES (0); ERROR: new row for relation "tp_12" violates check constraint "t_i_check" DETAIL: Failing row contains (0, virtual). diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out index 43ca299648e..5570508d271 100644 --- a/src/test/regress/expected/partition_split.out +++ b/src/test/regress/expected/partition_split.out @@ -15,19 +15,19 @@ CREATE TABLE sales_range (salesperson_id int, sales_date date) PARTITION BY RANG CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01'); CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01'); CREATE TABLE sales_others PARTITION OF sales_range DEFAULT; --- ERROR: relation "sales_xxx" does not exist +-- ERROR ALTER TABLE sales_range SPLIT PARTITION sales_xxx INTO (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'), PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01')); ERROR: relation "sales_xxx" does not exist --- ERROR: relation "sales_jan2022" already exists +-- ERROR ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_jan2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'), PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01')); ERROR: relation "sales_jan2022" already exists --- ERROR: invalid bound specification for a range partition +-- ERROR ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_jan2022 FOR VALUES IN ('2022-05-01', '2022-06-01'), PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), @@ -35,7 +35,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO ERROR: invalid bound specification for a range partition LINE 2: (PARTITION sales_jan2022 FOR VALUES IN ('2022-05-01', '202... ^ --- ERROR: empty range bound specified for partition "sales_mar2022" +-- ERROR 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-03-01') TO ('2022-02-01'), @@ -44,12 +44,11 @@ ERROR: empty range bound specified for partition "sales_mar2022" LINE 3: PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO... ^ DETAIL: Specified lower bound ('03-01-2022') is greater than or equal to upper bound ('02-01-2022'). ---ERROR: list of split partitions should contain at least two items +-- ERROR ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01')); ERROR: list of new partitions should contain at least two partitions --- ERROR: lower bound of partition "sales_feb2022" is not equal to lower bound of split partition "sales_feb_mar_apr2022" --- HINT: ALTER TABLE ... SPLIT PARTITION require combined bounds of new partitions must exactly match the bound of the split partition. +-- ERROR ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_feb2022 FOR VALUES FROM ('2022-01-01') TO ('2022-03-01'), PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), @@ -58,7 +57,7 @@ ERROR: lower bound of partition "sales_feb2022" is not equal to lower bound of LINE 2: (PARTITION sales_feb2022 FOR VALUES FROM ('2022-01-01') TO... ^ HINT: ALTER TABLE ... SPLIT PARTITION require combined bounds of new partitions must exactly match the bound of the split partition. --- ERROR: partition with name "sales_feb_mar_apr2022" is already used +-- ERROR -- (We can create partition with the same name as split partition, but can't create two partitions with the same name) ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'), @@ -67,7 +66,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO ERROR: partition with name "sales_feb_mar_apr2022" is already used LINE 3: PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03... ^ --- ERROR: partition with name "sales_feb2022" is already used +-- ERROR 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_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), @@ -75,7 +74,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO ERROR: partition with name "sales_feb2022" is already used LINE 3: PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO... ^ --- ERROR: partition with name "sales_feb2022" is already used +-- ERROR 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 partition_split_schema.sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), @@ -83,16 +82,14 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO ERROR: partition with name "sales_feb2022" is already used LINE 3: PARTITION partition_split_schema.sales_feb2022 FOR VALUES... ^ --- ERROR: ALTER action SPLIT PARTITION cannot be performed on relation "sales_feb_mar_apr2022" --- DETAIL: This operation is not supported for tables. +-- ERROR ALTER TABLE sales_feb_mar_apr2022 SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_jan2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'), PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01')); ERROR: ALTER action SPLIT PARTITION cannot be performed on relation "sales_feb_mar_apr2022" DETAIL: This operation is not supported for tables. --- ERROR: upper bound of partition "sales_apr2022" is not equal to upper bound of split partition "sales_feb_mar_apr2022" --- HINT: ALTER TABLE ... SPLIT PARTITION require combined bounds of new partitions must exactly match the bound of the split partition. +-- ERROR 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-03-01') TO ('2022-04-01'), @@ -101,20 +98,18 @@ ERROR: upper bound of partition "sales_apr2022" is not equal to upper bound of LINE 4: ... sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-0... ^ HINT: ALTER TABLE ... SPLIT PARTITION require combined bounds of new partitions must exactly match the bound of the split partition. --- ERROR: can not split to partition "sales_mar2022" together with partition "sales_feb2022" +-- ERROR 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 non-adjacent partitions "sales_mar2022" and "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" -HINT: ALTER TABLE ... SPLIT PARTITION requires the partition bounds to be adjacent. +DETAIL: Lower bound of partition "sales_mar2022" is not equal to upper bound of partition "sales_feb2022". -- Tests for spaces between partitions, them should be executed without DEFAULT partition ALTER TABLE sales_range DETACH PARTITION sales_others; --- ERROR: lower bound of partition "sales_feb2022" is not equal to lower bound of split partition "sales_feb_mar_apr2022" --- HINT: ALTER TABLE ... SPLIT PARTITION require combined bounds of new partitions must exactly match the bound of the split partition. +-- ERROR ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'), PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), @@ -150,8 +145,7 @@ DROP TABLE sales_others; CREATE TABLE sales_range (sales_date date) PARTITION BY RANGE (sales_date); CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01'); CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01'); --- ERROR: upper bound of partition "sales_apr2022" is not equal to upper bound of split partition "sales_feb_mar_apr2022" --- HINT: ALTER TABLE ... SPLIT PARTITION require combined bounds of new partitions must exactly match the bound of the split partition. +-- ERROR 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-03-01') TO ('2022-04-01'), @@ -461,63 +455,58 @@ DROP TABLE sales_range CASCADE; CREATE TABLE sales_range (salesperson_id INT, sales_date date) PARTITION BY RANGE (sales_date); CREATE TABLE sales_others PARTITION OF sales_range DEFAULT; -- sales_error intersects with sales_dec2021 (lower bound) --- ERROR: can not split to partition "sales_error" together with partition "sales_dec2021" +-- ERROR ALTER TABLE sales_range SPLIT PARTITION sales_others INTO (PARTITION sales_dec2021 FOR VALUES FROM ('2021-12-01') TO ('2022-01-01'), 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 non-adjacent partitions "sales_error" and "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" -HINT: ALTER TABLE ... SPLIT PARTITION requires the partition bounds to be adjacent. +DETAIL: Lower bound of partition "sales_error" is not equal to upper bound of partition "sales_dec2021". -- sales_error intersects with sales_feb2022 (upper bound) --- ERROR: can not split to partition "sales_feb2022" together with partition "sales_error" +-- ERROR ALTER TABLE sales_range SPLIT PARTITION sales_others INTO (PARTITION sales_dec2021 FOR VALUES FROM ('2021-12-01') TO ('2022-01-01'), 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 non-adjacent partitions "sales_feb2022" and "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" -HINT: ALTER TABLE ... SPLIT PARTITION requires the partition bounds to be adjacent. +DETAIL: Lower bound of partition "sales_feb2022" is not equal to upper bound of partition "sales_error". -- sales_error intersects with sales_dec2021 (inside bound) --- ERROR: can not split to partition "sales_error" together with partition "sales_dec2021" +-- ERROR ALTER TABLE sales_range SPLIT PARTITION sales_others INTO (PARTITION sales_dec2021 FOR VALUES FROM ('2021-12-01') TO ('2022-01-01'), 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 non-adjacent partitions "sales_error" and "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" -HINT: ALTER TABLE ... SPLIT PARTITION requires the partition bounds to be adjacent. +DETAIL: Lower bound of partition "sales_error" is not equal to upper bound of partition "sales_dec2021". -- sales_error intersects with sales_dec2021 (exactly the same bounds) --- ERROR: can not split to partition "sales_error" together with partition "sales_dec2021" +-- ERROR ALTER TABLE sales_range SPLIT PARTITION sales_others INTO (PARTITION sales_dec2021 FOR VALUES FROM ('2021-12-01') TO ('2022-01-01'), 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 non-adjacent partitions "sales_error" and "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" -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. +DETAIL: Lower bound of partition "sales_error" is not equal to upper bound of partition "sales_dec2021". +-- ERROR 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'), @@ -579,11 +568,11 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre FOREIGN KEY (salesperson_id) REFERENCES salespeople(salesperson_id) | sales_range_salesperson_id_fkey | {1} (2 rows) --- ERROR: new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check" +-- ERROR INSERT INTO sales_range VALUES (1, 0, '2022-03-11'); ERROR: new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check" DETAIL: Failing row contains (1, 0, 03-11-2022). --- ERROR: insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesperson_id_fkey" +-- ERROR INSERT INTO sales_range VALUES (-1, 10, '2022-03-11'); ERROR: insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesperson_id_fkey" DETAIL: Key (salesperson_id)=(-1) is not present in table "salespeople". @@ -637,7 +626,7 @@ SELECT tableoid::regclass, * FROM salespeople ORDER BY tableoid::regclass::text salespeople30_40 | 30 | Ford (5 rows) --- ERROR: insert or update on table "sales" violates foreign key constraint "sales_salesperson_id_fkey" +-- ERROR INSERT INTO sales VALUES (40, 50, '2022-03-04'); ERROR: insert or update on table "sales" violates foreign key constraint "sales_salesperson_id_fkey" DETAIL: Key (salesperson_id)=(40) is not present in table "salespeople". @@ -857,7 +846,7 @@ CREATE TABLE sales_list (sales_state VARCHAR(20)) PARTITION BY LIST (sales_state CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Petersburg', 'Helsinki'); CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Beijing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok'); CREATE TABLE sales_others PARTITION OF sales_list DEFAULT; --- ERROR: new partition "sales_east" would overlap with another (not split) partition "sales_nord" +-- ERROR ALTER TABLE sales_list SPLIT PARTITION sales_all INTO (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'), PARTITION sales_east FOR VALUES IN ('Beijing', 'Delhi', 'Vladivostok', 'Helsinki'), @@ -865,7 +854,7 @@ ALTER TABLE sales_list SPLIT PARTITION sales_all INTO ERROR: new partition "sales_east" would overlap with another (not split) partition "sales_nord" LINE 3: ...FOR VALUES IN ('Beijing', 'Delhi', 'Vladivostok', 'Helsinki'... ^ --- ERROR: new partition "sales_west" would overlap with another new partition "sales_central" +-- ERROR ALTER TABLE sales_list SPLIT PARTITION sales_all INTO (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'), PARTITION sales_east FOR VALUES IN ('Beijing', 'Delhi', 'Vladivostok'), @@ -873,7 +862,7 @@ ALTER TABLE sales_list SPLIT PARTITION sales_all INTO ERROR: new partition "sales_west" would overlap with another new partition "sales_central" LINE 2: (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York',... ^ --- ERROR: new partition "sales_west" cannot have NULL value because split partition "sales_all" does not have +-- ERROR ALTER TABLE sales_list SPLIT PARTITION sales_all INTO (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid', NULL), PARTITION sales_east FOR VALUES IN ('Beijing', 'Delhi', 'Vladivostok'), @@ -881,7 +870,7 @@ ALTER TABLE sales_list SPLIT PARTITION sales_all INTO ERROR: new partition "sales_west" cannot have NULL value because split partition "sales_all" does not have LINE 2: ...s_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid', NULL), ^ --- ERROR: new partition "sales_west" cannot have this value because split partition "sales_all" does not have +-- ERROR ALTER TABLE sales_list SPLIT PARTITION sales_all INTO (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid', 'Melbourne'), PARTITION sales_east FOR VALUES IN ('Beijing', 'Delhi', 'Vladivostok'), @@ -889,20 +878,21 @@ ALTER TABLE sales_list SPLIT PARTITION sales_all INTO 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... ^ --- ERROR: new partition cannot be DEFAULT because DEFAULT partition "sales_others" already exists +-- ERROR ALTER TABLE sales_list SPLIT PARTITION sales_all INTO (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid', 'Melbourne'), 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); CREATE TABLE t1 PARTITION OF t FOR VALUES in ('0', '1'); --- ERROR: new partition "x" would overlap with another new partition "x1" +-- ERROR ALTER TABLE t SPLIT PARTITION t1 INTO (PARTITION x FOR VALUES IN ('0'), PARTITION x1 FOR VALUES IN ('0.0', '1')); @@ -918,30 +908,28 @@ DROP TABLE t; CREATE TABLE sales_list(sales_state VARCHAR(20)) PARTITION BY LIST (sales_state); CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo'); CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Beijing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL); --- ERROR: new partitions combined partition bounds do not contain value (NULL) but split partition "sales_all" does --- HINT: ALTER TABLE ... SPLIT PARTITION require combined bounds of new partitions must exactly match the bound of the split partition. +-- ERROR ALTER TABLE sales_list SPLIT PARTITION sales_all INTO (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'), PARTITION sales_east FOR VALUES IN ('Beijing', 'Delhi', 'Vladivostok'), PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv')); ERROR: new partitions combined partition bounds do not contain value (NULL) but split partition "sales_all" does HINT: ALTER TABLE ... SPLIT PARTITION require combined bounds of new partitions must exactly match the bound of the split partition. --- ERROR: new partitions combined partition bounds do not contain value ('Kyiv'::character varying(20)) but split partition "sales_all" does --- HINT: ALTER TABLE ... SPLIT PARTITION require combined bounds of new partitions must exactly match the bound of the split partition. +-- ERROR ALTER TABLE sales_list SPLIT PARTITION sales_all INTO (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'), PARTITION sales_east FOR VALUES IN ('Beijing', 'Delhi', 'Vladivostok'), PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', NULL)); ERROR: new partitions combined partition bounds do not contain value ('Kyiv'::character varying(20)) but split partition "sales_all" does HINT: ALTER TABLE ... SPLIT PARTITION require combined bounds of new partitions must exactly match the bound of the split partition. --- ERROR DEFAULT partition should be one +-- ERROR ALTER TABLE sales_list SPLIT PARTITION sales_all INTO (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'), PARTITION sales_east FOR VALUES IN ('Beijing', 'Delhi', 'Vladivostok'), 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; @@ -1202,7 +1190,7 @@ DROP TABLE sales_range; CREATE TABLE t1(i int, t text) PARTITION BY LIST (t); CREATE TABLE t1pa PARTITION OF t1 FOR VALUES IN ('A'); CREATE TABLE t2 (i int, t text) PARTITION BY RANGE (t); --- ERROR: relation "t1pa" is not a partition of relation "t2" +-- ERROR ALTER TABLE t2 SPLIT PARTITION t1pa INTO (PARTITION t2a FOR VALUES FROM ('A') TO ('B'), PARTITION t2b FOR VALUES FROM ('B') TO ('C')); @@ -1224,7 +1212,7 @@ SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid) tp_0_2 | FOR VALUES FROM (0) TO (2) | t (1 row) --- ERROR: cannot create a permanent relation as partition of temporary relation "t" +-- ERROR ALTER TABLE t SPLIT PARTITION tp_0_2 INTO (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1), PARTITION tp_1_2 FOR VALUES FROM (1) TO (2)); @@ -1455,12 +1443,12 @@ DROP ROLE regress_partition_split_bob; CREATE TABLE t (i int) PARTITION BY HASH(i); CREATE TABLE tp1 PARTITION OF t FOR VALUES WITH (MODULUS 2, REMAINDER 0); CREATE TABLE tp2 PARTITION OF t FOR VALUES WITH (MODULUS 2, REMAINDER 1); --- ERROR: partition of hash-partitioned table cannot be split +-- ERROR ALTER TABLE t SPLIT PARTITION tp1 INTO (PARTITION tp1_1 FOR VALUES WITH (MODULUS 4, REMAINDER 0), PARTITION tp1_2 FOR VALUES WITH (MODULUS 4, REMAINDER 2)); ERROR: partition of hash-partitioned table cannot be split --- ERROR: list of new partitions should contain at least two partitions +-- ERROR ALTER TABLE t SPLIT PARTITION tp1 INTO (PARTITION tp1_1 FOR VALUES WITH (MODULUS 4, REMAINDER 0)); ERROR: list of new partitions should contain at least two partitions diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql index a211fee2ad1..0f7977ec79a 100644 --- a/src/test/regress/sql/partition_merge.sql +++ b/src/test/regress/sql/partition_merge.sql @@ -27,19 +27,17 @@ ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT; --- ERROR: partition with name "sales_feb2022" is already used +-- ERROR ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022; --- ERROR: "sales_apr2022" is not a table +-- ERROR ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022; --- 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 -- (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_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 -- (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: partition with name "sales_feb2022" is already used +-- ERROR ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, partitions_merge_schema.sales_feb2022) INTO sales_feb_mar_apr2022; --ERROR, sales_apr_2 already exists ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_jan2022) INTO sales_apr_2; @@ -357,11 +355,11 @@ CREATE TABLE sales_others2 PARTITION OF sales_list2 DEFAULT; CREATE TABLE sales_external (LIKE sales_list); CREATE TABLE sales_external2 (vch VARCHAR(5)); --- ERROR: "sales_external" is not a partition of partitioned table "sales_list" +-- ERROR ALTER TABLE sales_list MERGE PARTITIONS (sales_west, sales_east, sales_external) INTO sales_all; --- ERROR: "sales_external2" is not a partition of partitioned table "sales_list" +-- ERROR ALTER TABLE sales_list MERGE PARTITIONS (sales_west, sales_east, sales_external2) INTO sales_all; --- ERROR: relation "sales_nord2" is not a partition of relation "sales_list" +-- ERROR ALTER TABLE sales_list MERGE PARTITIONS (sales_west, sales_nord2, sales_east) INTO sales_all; DROP TABLE sales_external2; @@ -438,9 +436,9 @@ CREATE TABLE t2 (i int, t text) PARTITION BY RANGE (t); CREATE TABLE t2pa PARTITION OF t2 FOR VALUES FROM ('A') TO ('C'); CREATE TABLE t3 (i int, t text); --- ERROR: relation "t1p1" is not a partition of relation "t2" +-- ERROR ALTER TABLE t2 MERGE PARTITIONS (t1p1, t2pa) INTO t2p; --- ERROR: "t3" is not a partition of partitioned table "t2" +-- ERROR ALTER TABLE t2 MERGE PARTITIONS (t2pa, t3) INTO t2p; DROP TABLE t3; @@ -481,7 +479,7 @@ ALTER TABLE t MERGE PARTITIONS (tp_0_2, tp_2_3) INTO pg_temp.tp_0_3; -- Partition should be temporary. EXECUTE get_partition_info('{t}'); --- ERROR: cannot create a permanent relation as partition of temporary relation "t" +-- ERROR ALTER TABLE t MERGE PARTITIONS (tp_0_3, tp_3_4) INTO tp_0_4; ROLLBACK; @@ -567,19 +565,19 @@ CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1); CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2); SET SESSION AUTHORIZATION regress_partition_merge_bob; --- ERROR: must be owner of table t +-- ERROR ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2; RESET SESSION AUTHORIZATION; ALTER TABLE t OWNER TO regress_partition_merge_bob; SET SESSION AUTHORIZATION regress_partition_merge_bob; --- ERROR: must be owner of table tp_0_1 +-- ERROR ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2; RESET SESSION AUTHORIZATION; ALTER TABLE tp_0_1 OWNER TO regress_partition_merge_bob; SET SESSION AUTHORIZATION regress_partition_merge_bob; --- ERROR: must be owner of table tp_1_2 +-- ERROR ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2; RESET SESSION AUTHORIZATION; @@ -607,7 +605,7 @@ ALTER TABLE t ATTACH PARTITION tp_1_2 FOR VALUES FROM (1) TO (2); -- Owner is 'regress_partition_merge_bob': \dt tp_1_2 --- ERROR: partitions being merged have different owners +-- ERROR ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2; DROP TABLE t; @@ -622,10 +620,10 @@ CREATE TABLE t (i int) PARTITION BY HASH(i); CREATE TABLE tp1 PARTITION OF t FOR VALUES WITH (MODULUS 2, REMAINDER 0); CREATE TABLE tp2 PARTITION OF t FOR VALUES WITH (MODULUS 2, REMAINDER 1); --- ERROR: partition of hash-partitioned table cannot be merged +-- ERROR ALTER TABLE t MERGE PARTITIONS (tp1, tp2) INTO tp3; --- ERROR: list of partitions to be merged should include at least two partitions +-- ERROR ALTER TABLE t MERGE PARTITIONS (tp1) INTO tp3; DROP TABLE t; @@ -712,7 +710,7 @@ ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2; -- Should be NOT VALID FOREIGN KEY \d tp_0_2 --- ERROR: insert or update on table "t_fk" violates foreign key constraint "t_fk_i_fkey" +-- ERROR ALTER TABLE t_fk VALIDATE CONSTRAINT t_fk_i_fkey; DROP TABLE t_fk; @@ -731,7 +729,7 @@ ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2; -- Should be NOT ENFORCED FOREIGN KEY \d tp_0_2 --- ERROR: insert or update on table "t_fk" violates foreign key constraint "t_fk_i_fkey" +-- ERROR ALTER TABLE t_fk ALTER CONSTRAINT t_fk_i_fkey ENFORCED; DROP TABLE t_fk; @@ -774,7 +772,7 @@ INSERT INTO t VALUES (5), (15); ALTER TABLE t MERGE PARTITIONS (tp_1, tp_2) INTO tp_12; INSERT INTO t VALUES (16); --- ERROR: new row for relation "tp_12" violates check constraint "t_i_check" +-- ERROR INSERT INTO t VALUES (0); -- Should be 3 rows: (5), (15), (16): SELECT i FROM t ORDER BY i; diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql index 44fcf208ac6..a110fc87867 100644 --- a/src/test/regress/sql/partition_split.sql +++ b/src/test/regress/sql/partition_split.sql @@ -19,75 +19,72 @@ CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01 CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01'); CREATE TABLE sales_others PARTITION OF sales_range DEFAULT; --- ERROR: relation "sales_xxx" does not exist +-- ERROR ALTER TABLE sales_range SPLIT PARTITION sales_xxx INTO (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'), PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01')); --- ERROR: relation "sales_jan2022" already exists +-- ERROR ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_jan2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'), PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01')); --- ERROR: invalid bound specification for a range partition +-- ERROR ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_jan2022 FOR VALUES IN ('2022-05-01', '2022-06-01'), PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01')); --- ERROR: empty range bound specified for partition "sales_mar2022" +-- ERROR 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-03-01') TO ('2022-02-01'), PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01')); ---ERROR: list of split partitions should contain at least two items +-- ERROR ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01')); --- ERROR: lower bound of partition "sales_feb2022" is not equal to lower bound of split partition "sales_feb_mar_apr2022" --- HINT: ALTER TABLE ... SPLIT PARTITION require combined bounds of new partitions must exactly match the bound of the split partition. +-- ERROR ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_feb2022 FOR VALUES FROM ('2022-01-01') TO ('2022-03-01'), PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01')); --- ERROR: partition with name "sales_feb_mar_apr2022" is already used +-- ERROR -- (We can create partition with the same name as split partition, but can't create two partitions with the same name) ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'), PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01')); --- ERROR: partition with name "sales_feb2022" is already used +-- ERROR 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_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01')); --- ERROR: partition with name "sales_feb2022" is already used +-- ERROR 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 partition_split_schema.sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01')); --- ERROR: ALTER action SPLIT PARTITION cannot be performed on relation "sales_feb_mar_apr2022" --- DETAIL: This operation is not supported for tables. +-- ERROR ALTER TABLE sales_feb_mar_apr2022 SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_jan2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'), PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01')); --- ERROR: upper bound of partition "sales_apr2022" is not equal to upper bound of split partition "sales_feb_mar_apr2022" --- HINT: ALTER TABLE ... SPLIT PARTITION require combined bounds of new partitions must exactly match the bound of the split partition. +-- ERROR 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-03-01') TO ('2022-04-01'), PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-01')); --- ERROR: can not split to partition "sales_mar2022" together with partition "sales_feb2022" +-- ERROR 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'), @@ -96,8 +93,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO -- Tests for spaces between partitions, them should be executed without DEFAULT partition ALTER TABLE sales_range DETACH PARTITION sales_others; --- ERROR: lower bound of partition "sales_feb2022" is not equal to lower bound of split partition "sales_feb_mar_apr2022" --- HINT: ALTER TABLE ... SPLIT PARTITION require combined bounds of new partitions must exactly match the bound of the split partition. +-- ERROR ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'), PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), @@ -121,8 +117,7 @@ CREATE TABLE sales_range (sales_date date) PARTITION BY RANGE (sales_date); CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01'); CREATE TABLE sales_feb_mar_apr2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-05-01'); --- ERROR: upper bound of partition "sales_apr2022" is not equal to upper bound of split partition "sales_feb_mar_apr2022" --- HINT: ALTER TABLE ... SPLIT PARTITION require combined bounds of new partitions must exactly match the bound of the split partition. +-- ERROR 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-03-01') TO ('2022-04-01'), @@ -299,7 +294,7 @@ CREATE TABLE sales_range (salesperson_id INT, sales_date date) PARTITION BY RANG CREATE TABLE sales_others PARTITION OF sales_range DEFAULT; -- sales_error intersects with sales_dec2021 (lower bound) --- ERROR: can not split to partition "sales_error" together with partition "sales_dec2021" +-- ERROR ALTER TABLE sales_range SPLIT PARTITION sales_others INTO (PARTITION sales_dec2021 FOR VALUES FROM ('2021-12-01') TO ('2022-01-01'), PARTITION sales_error FOR VALUES FROM ('2021-12-30') TO ('2022-02-01'), @@ -307,7 +302,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO PARTITION sales_others DEFAULT); -- sales_error intersects with sales_feb2022 (upper bound) --- ERROR: can not split to partition "sales_feb2022" together with partition "sales_error" +-- ERROR ALTER TABLE sales_range SPLIT PARTITION sales_others INTO (PARTITION sales_dec2021 FOR VALUES FROM ('2021-12-01') TO ('2022-01-01'), PARTITION sales_error FOR VALUES FROM ('2022-01-01') TO ('2022-02-02'), @@ -315,7 +310,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO PARTITION sales_others DEFAULT); -- sales_error intersects with sales_dec2021 (inside bound) --- ERROR: can not split to partition "sales_error" together with partition "sales_dec2021" +-- ERROR ALTER TABLE sales_range SPLIT PARTITION sales_others INTO (PARTITION sales_dec2021 FOR VALUES FROM ('2021-12-01') TO ('2022-01-01'), PARTITION sales_error FOR VALUES FROM ('2021-12-10') TO ('2021-12-20'), @@ -323,15 +318,14 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO PARTITION sales_others DEFAULT); -- sales_error intersects with sales_dec2021 (exactly the same bounds) --- ERROR: can not split to partition "sales_error" together with partition "sales_dec2021" +-- ERROR ALTER TABLE sales_range SPLIT PARTITION sales_others INTO (PARTITION sales_dec2021 FOR VALUES FROM ('2021-12-01') TO ('2022-01-01'), 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 DEFAULT partition "sales_others" --- HINT: To split DEFAULT partition one of the new partition must be DEFAULT. +-- ERROR 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'), @@ -385,9 +379,9 @@ SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conre SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_mar2022'::regclass::oid ORDER BY conname COLLATE "C"; SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_apr2022'::regclass::oid ORDER BY conname COLLATE "C"; --- ERROR: new row for relation "sales_mar2022" violates check constraint "sales_range_sales_amount_check" +-- ERROR INSERT INTO sales_range VALUES (1, 0, '2022-03-11'); --- ERROR: insert or update on table "sales_mar2022" violates foreign key constraint "sales_range_salesperson_id_fkey" +-- ERROR INSERT INTO sales_range VALUES (-1, 10, '2022-03-11'); -- ok INSERT INTO sales_range VALUES (1, 10, '2022-03-11'); @@ -430,7 +424,7 @@ ALTER TABLE salespeople SPLIT PARTITION salespeople10_40 INTO SELECT tableoid::regclass, * FROM salespeople ORDER BY tableoid::regclass::text COLLATE "C", salesperson_id; --- ERROR: insert or update on table "sales" violates foreign key constraint "sales_salesperson_id_fkey" +-- ERROR INSERT INTO sales VALUES (40, 50, '2022-03-04'); -- ok INSERT INTO sales VALUES (30, 50, '2022-03-04'); @@ -608,31 +602,31 @@ CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Oslo', 'St. Pete CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Beijing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok'); CREATE TABLE sales_others PARTITION OF sales_list DEFAULT; --- ERROR: new partition "sales_east" would overlap with another (not split) partition "sales_nord" +-- ERROR ALTER TABLE sales_list SPLIT PARTITION sales_all INTO (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'), PARTITION sales_east FOR VALUES IN ('Beijing', 'Delhi', 'Vladivostok', 'Helsinki'), PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv')); --- ERROR: new partition "sales_west" would overlap with another new partition "sales_central" +-- ERROR ALTER TABLE sales_list SPLIT PARTITION sales_all INTO (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'), PARTITION sales_east FOR VALUES IN ('Beijing', 'Delhi', 'Vladivostok'), PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Lisbon', 'Kyiv')); --- ERROR: new partition "sales_west" cannot have NULL value because split partition "sales_all" does not have +-- ERROR ALTER TABLE sales_list SPLIT PARTITION sales_all INTO (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid', NULL), PARTITION sales_east FOR VALUES IN ('Beijing', 'Delhi', 'Vladivostok'), PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv')); --- ERROR: new partition "sales_west" cannot have this value because split partition "sales_all" does not have +-- ERROR ALTER TABLE sales_list SPLIT PARTITION sales_all INTO (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid', 'Melbourne'), PARTITION sales_east FOR VALUES IN ('Beijing', 'Delhi', 'Vladivostok'), PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv')); --- ERROR: new partition cannot be DEFAULT because DEFAULT partition "sales_others" already exists +-- ERROR ALTER TABLE sales_list SPLIT PARTITION sales_all INTO (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid', 'Melbourne'), PARTITION sales_east FOR VALUES IN ('Beijing', 'Delhi', 'Vladivostok'), @@ -644,7 +638,7 @@ 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); CREATE TABLE t1 PARTITION OF t FOR VALUES in ('0', '1'); --- ERROR: new partition "x" would overlap with another new partition "x1" +-- ERROR ALTER TABLE t SPLIT PARTITION t1 INTO (PARTITION x FOR VALUES IN ('0'), PARTITION x1 FOR VALUES IN ('0.0', '1')); @@ -660,21 +654,19 @@ CREATE TABLE sales_list(sales_state VARCHAR(20)) PARTITION BY LIST (sales_state) CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo'); CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Beijing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL); --- ERROR: new partitions combined partition bounds do not contain value (NULL) but split partition "sales_all" does --- HINT: ALTER TABLE ... SPLIT PARTITION require combined bounds of new partitions must exactly match the bound of the split partition. +-- ERROR ALTER TABLE sales_list SPLIT PARTITION sales_all INTO (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'), PARTITION sales_east FOR VALUES IN ('Beijing', 'Delhi', 'Vladivostok'), PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv')); --- ERROR: new partitions combined partition bounds do not contain value ('Kyiv'::character varying(20)) but split partition "sales_all" does --- HINT: ALTER TABLE ... SPLIT PARTITION require combined bounds of new partitions must exactly match the bound of the split partition. +-- ERROR ALTER TABLE sales_list SPLIT PARTITION sales_all INTO (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'), PARTITION sales_east FOR VALUES IN ('Beijing', 'Delhi', 'Vladivostok'), PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', NULL)); --- ERROR DEFAULT partition should be one +-- ERROR ALTER TABLE sales_list SPLIT PARTITION sales_all INTO (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'), PARTITION sales_east FOR VALUES IN ('Beijing', 'Delhi', 'Vladivostok'), @@ -849,7 +841,7 @@ CREATE TABLE t1(i int, t text) PARTITION BY LIST (t); CREATE TABLE t1pa PARTITION OF t1 FOR VALUES IN ('A'); CREATE TABLE t2 (i int, t text) PARTITION BY RANGE (t); --- ERROR: relation "t1pa" is not a partition of relation "t2" +-- ERROR ALTER TABLE t2 SPLIT PARTITION t1pa INTO (PARTITION t2a FOR VALUES FROM ('A') TO ('B'), PARTITION t2b FOR VALUES FROM ('B') TO ('C')); @@ -868,7 +860,7 @@ SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid) WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text COLLATE "C"; --- ERROR: cannot create a permanent relation as partition of temporary relation "t" +-- ERROR ALTER TABLE t SPLIT PARTITION tp_0_2 INTO (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1), PARTITION tp_1_2 FOR VALUES FROM (1) TO (2)); @@ -1033,12 +1025,12 @@ CREATE TABLE t (i int) PARTITION BY HASH(i); CREATE TABLE tp1 PARTITION OF t FOR VALUES WITH (MODULUS 2, REMAINDER 0); CREATE TABLE tp2 PARTITION OF t FOR VALUES WITH (MODULUS 2, REMAINDER 1); --- ERROR: partition of hash-partitioned table cannot be split +-- ERROR ALTER TABLE t SPLIT PARTITION tp1 INTO (PARTITION tp1_1 FOR VALUES WITH (MODULUS 4, REMAINDER 0), PARTITION tp1_2 FOR VALUES WITH (MODULUS 4, REMAINDER 2)); --- ERROR: list of new partitions should contain at least two partitions +-- ERROR ALTER TABLE t SPLIT PARTITION tp1 INTO (PARTITION tp1_1 FOR VALUES WITH (MODULUS 4, REMAINDER 0)); -- 2.34.1