v2-0001-Fix-duplicate-errmsg-in-ALTER-TABLE-SPLIT-PARTITION.patch
application/octet-stream
Filename: v2-0001-Fix-duplicate-errmsg-in-ALTER-TABLE-SPLIT-PARTITION.patch
Type: application/octet-stream
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
Series: patch v2-0001
| File | + | − |
|---|---|---|
| src/backend/commands/tablecmds.c | 1 | 1 |
| src/backend/parser/parse_utilcmd.c | 6 | 6 |
| src/backend/partitioning/partbounds.c | 4 | 6 |
| src/test/regress/expected/partition_merge.out | 4 | 28 |
| src/test/regress/expected/partition_split.out | 15 | 62 |
| src/test/regress/sql/partition_merge.sql | 0 | 22 |
| src/test/regress/sql/partition_split.sql | 0 | 43 |
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..035660bb7cb 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,10 +3662,10 @@ 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",
- get_rel_name(defaultPartOid)),
+ 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..4480e7e5116 100644
--- a/src/test/regress/expected/partition_merge.out
+++ b/src/test/regress/expected/partition_merge.out
@@ -21,30 +21,21 @@ 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
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
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"
-- (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".
-- (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".
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 +471,12 @@ 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"
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"
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"
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 +618,9 @@ 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"
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"
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 +676,6 @@ 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"
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 +791,16 @@ 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
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
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
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 +834,6 @@ 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
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 +845,8 @@ 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
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
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 +978,6 @@ 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"
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 +1004,6 @@ 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"
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 +1047,6 @@ 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"
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..21bfddfc47f 100644
--- a/src/test/regress/expected/partition_split.out
+++ b/src/test/regress/expected/partition_split.out
@@ -15,19 +15,16 @@ 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
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
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
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 +32,6 @@ 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"
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 +40,9 @@ 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
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.
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 +51,6 @@ 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
-- (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 +59,6 @@ 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
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 +66,6 @@ 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
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 +73,12 @@ 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.
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.
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 +87,16 @@ 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"
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.
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 +132,6 @@ 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.
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 +441,53 @@ 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"
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"
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"
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"
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".
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 +549,9 @@ 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"
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"
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 +605,6 @@ 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"
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 +824,6 @@ 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"
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 +831,6 @@ 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"
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 +838,6 @@ 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
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 +845,6 @@ 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
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 +852,19 @@ 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
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"
ALTER TABLE t SPLIT PARTITION t1 INTO
(PARTITION x FOR VALUES IN ('0'),
PARTITION x1 FOR VALUES IN ('0.0', '1'));
@@ -918,30 +880,25 @@ 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.
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.
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
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 +1159,6 @@ 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"
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 +1180,6 @@ 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"
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 +1410,10 @@ 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
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
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..7b117fa34e0 100644
--- a/src/test/regress/sql/partition_merge.sql
+++ b/src/test/regress/sql/partition_merge.sql
@@ -27,19 +27,12 @@ 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
ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022;
--- 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: 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"
-- (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"
-- (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
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 +350,8 @@ 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"
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"
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"
ALTER TABLE sales_list MERGE PARTITIONS (sales_west, sales_nord2, sales_east) INTO sales_all;
DROP TABLE sales_external2;
@@ -438,9 +428,7 @@ 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"
ALTER TABLE t2 MERGE PARTITIONS (t1p1, t2pa) INTO t2p;
--- ERROR: "t3" is not a partition of partitioned table "t2"
ALTER TABLE t2 MERGE PARTITIONS (t2pa, t3) INTO t2p;
DROP TABLE t3;
@@ -481,7 +469,6 @@ 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"
ALTER TABLE t MERGE PARTITIONS (tp_0_3, tp_3_4) INTO tp_0_4;
ROLLBACK;
@@ -567,19 +554,16 @@ 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
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
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
ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
RESET SESSION AUTHORIZATION;
@@ -607,7 +591,6 @@ 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
ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
DROP TABLE t;
@@ -622,10 +605,8 @@ 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
ALTER TABLE t MERGE PARTITIONS (tp1, tp2) INTO tp3;
--- ERROR: list of partitions to be merged should include at least two partitions
ALTER TABLE t MERGE PARTITIONS (tp1) INTO tp3;
DROP TABLE t;
@@ -712,7 +693,6 @@ 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"
ALTER TABLE t_fk VALIDATE CONSTRAINT t_fk_i_fkey;
DROP TABLE t_fk;
@@ -731,7 +711,6 @@ 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"
ALTER TABLE t_fk ALTER CONSTRAINT t_fk_i_fkey ENFORCED;
DROP TABLE t_fk;
@@ -774,7 +753,6 @@ 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"
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..dd976519ee2 100644
--- a/src/test/regress/sql/partition_split.sql
+++ b/src/test/regress/sql/partition_split.sql
@@ -19,75 +19,60 @@ 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
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
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
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"
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
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.
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
-- (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
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
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.
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.
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"
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 +81,6 @@ 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.
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 +104,6 @@ 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.
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 +280,6 @@ 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"
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 +287,6 @@ 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"
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 +294,6 @@ 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"
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 +301,12 @@ 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"
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.
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 +360,7 @@ 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"
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"
INSERT INTO sales_range VALUES (-1, 10, '2022-03-11');
-- ok
INSERT INTO sales_range VALUES (1, 10, '2022-03-11');
@@ -430,7 +403,6 @@ 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"
INSERT INTO sales VALUES (40, 50, '2022-03-04');
-- ok
INSERT INTO sales VALUES (30, 50, '2022-03-04');
@@ -608,31 +580,26 @@ 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"
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"
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
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
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
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 +611,6 @@ 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"
ALTER TABLE t SPLIT PARTITION t1 INTO
(PARTITION x FOR VALUES IN ('0'),
PARTITION x1 FOR VALUES IN ('0.0', '1'));
@@ -660,21 +626,16 @@ 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.
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.
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
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 +810,6 @@ 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"
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 +828,6 @@ 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"
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 +992,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 split
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
ALTER TABLE t SPLIT PARTITION tp1 INTO
(PARTITION tp1_1 FOR VALUES WITH (MODULUS 4, REMAINDER 0));