Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9e8bfc7

Browse files
committed
check that table is partitioned by RANGE in create_single_range_partition()
1 parent 0184282 commit 9e8bfc7

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

expected/pathman_calamity.out

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,19 @@ SELECT count(*) FROM calamity.part_test;
102102

103103
DELETE FROM calamity.part_test;
104104
/* test function create_single_range_partition() */
105-
SELECT create_single_range_partition(NULL, NULL::INT4, NULL); /* not ok */
105+
SELECT create_single_range_partition(NULL, NULL::INT4, NULL); /* not ok */
106106
ERROR: 'parent_relid' should not be NULL
107+
SELECT create_single_range_partition('pg_class', NULL::INT4, NULL); /* not ok */
108+
ERROR: table "pg_class" is not partitioned by RANGE
109+
SELECT add_to_pathman_config('calamity.part_test', 'val');
110+
add_to_pathman_config
111+
-----------------------
112+
t
113+
(1 row)
114+
115+
SELECT create_single_range_partition('calamity.part_test', NULL::INT4, NULL); /* not ok */
116+
ERROR: table "part_test" is not partitioned by RANGE
117+
DELETE FROM pathman_config WHERE partrel = 'calamity.part_test'::REGCLASS;
107118
/* test function create_range_partitions_internal() */
108119
SELECT create_range_partitions_internal(NULL, '{}'::INT[], NULL, NULL); /* not ok */
109120
ERROR: 'parent_relid' should not be NULL

sql/pathman_calamity.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ DELETE FROM calamity.part_test;
3737

3838

3939
/* test function create_single_range_partition() */
40-
SELECT create_single_range_partition(NULL, NULL::INT4, NULL); /* not ok */
40+
SELECT create_single_range_partition(NULL, NULL::INT4, NULL); /* not ok */
41+
SELECT create_single_range_partition('pg_class', NULL::INT4, NULL); /* not ok */
42+
43+
SELECT add_to_pathman_config('calamity.part_test', 'val');
44+
SELECT create_single_range_partition('calamity.part_test', NULL::INT4, NULL); /* not ok */
45+
DELETE FROM pathman_config WHERE partrel = 'calamity.part_test'::REGCLASS;
46+
4147

4248
/* test function create_range_partitions_internal() */
4349
SELECT create_range_partitions_internal(NULL, '{}'::INT[], NULL, NULL); /* not ok */

src/pl_range_funcs.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ create_single_range_partition_pl(PG_FUNCTION_ARGS)
100100
RangeVar *partition_name_rv;
101101
char *tablespace;
102102

103+
Datum values[Natts_pathman_config];
104+
bool isnull[Natts_pathman_config];
105+
103106

104107
/* Handle 'parent_relid' */
105108
if (!PG_ARGISNULL(0))
@@ -109,6 +112,15 @@ create_single_range_partition_pl(PG_FUNCTION_ARGS)
109112
else ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
110113
errmsg("'parent_relid' should not be NULL")));
111114

115+
/* Check that table is partitioned by RANGE */
116+
if (!pathman_config_contains_relation(parent_relid, values, isnull, NULL, NULL) ||
117+
DatumGetPartType(values[Anum_pathman_config_parttype - 1]) != PT_RANGE)
118+
{
119+
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
120+
errmsg("table \"%s\" is not partitioned by RANGE",
121+
get_rel_name_or_relid(parent_relid))));
122+
}
123+
112124
bounds_type = get_fn_expr_argtype(fcinfo->flinfo, 1);
113125

114126
start = PG_ARGISNULL(1) ?

0 commit comments

Comments
 (0)