59
59
p_attribute := lower (p_attribute);
60
60
PERFORM @extschema@.common_relation_checks(parent_relid, p_attribute);
61
61
62
+ IF p_count< 0 THEN
63
+ RAISE EXCEPTION' Partitions count must not be less than zero' ;
64
+ END IF;
65
+
62
66
/* Try to determine partitions count if not set*/
63
67
IF p_count ISNULL THEN
64
68
EXECUTE format(' SELECT count(*), max(%s) FROM %s' , p_attribute, parent_relid)
@@ -76,13 +80,19 @@ BEGIN
76
80
END LOOP;
77
81
END IF;
78
82
79
- /* Check boundaries*/
80
- EXECUTE format(' SELECT @extschema@.check_boundaries(' ' %s' ' ,' ' %s' ' ,' ' %s' ' ,' ' %s' ' ::%s)' ,
81
- parent_relid,
82
- p_attribute,
83
- p_start_value,
84
- p_start_value+ p_interval* p_count,
85
- pg_typeof(p_start_value));
83
+ /*
84
+ * In case when user doesn't want to automatically create partitions
85
+ * and specifies partition count as 0 then do not check boundaries
86
+ */
87
+ IF p_count!= 0 THEN
88
+ /* Check boundaries*/
89
+ EXECUTE format(' SELECT @extschema@.check_boundaries(' ' %s' ' ,' ' %s' ' ,' ' %s' ' ,' ' %s' ' ::%s)' ,
90
+ parent_relid,
91
+ p_attribute,
92
+ p_start_value,
93
+ p_start_value+ p_interval* p_count,
94
+ pg_typeof(p_start_value));
95
+ END IF;
86
96
87
97
SELECT * INTO v_plain_schema, v_plain_relname
88
98
FROM @extschema@.get_plain_schema_and_relname(parent_relid);
@@ -147,8 +157,8 @@ BEGIN
147
157
p_attribute := lower (p_attribute);
148
158
PERFORM @extschema@.common_relation_checks(parent_relid, p_attribute);
149
159
150
- IF p_count<= 0 THEN
151
- RAISE EXCEPTION' Partitions count must begreater than zero' ;
160
+ IF p_count< 0 THEN
161
+ RAISE EXCEPTION' Partitions count mustnot beless than zero' ;
152
162
END IF;
153
163
154
164
/* Try to determine partitions count if not set*/
@@ -172,11 +182,17 @@ BEGIN
172
182
END LOOP;
173
183
END IF;
174
184
175
- /* check boundaries*/
176
- PERFORM @extschema@.check_boundaries(parent_relid,
177
- p_attribute,
178
- p_start_value,
179
- p_start_value+ p_interval* p_count);
185
+ /*
186
+ * In case when user doesn't want to automatically create partitions
187
+ * and specifies partition count as 0 then do not check boundaries
188
+ */
189
+ IF p_count!= 0 THEN
190
+ /* check boundaries*/
191
+ PERFORM @extschema@.check_boundaries(parent_relid,
192
+ p_attribute,
193
+ p_start_value,
194
+ p_start_value+ p_interval* p_count);
195
+ END IF;
180
196
181
197
SELECT * INTO v_plain_schema, v_plain_relname
182
198
FROM @extschema@.get_plain_schema_and_relname(parent_relid);
@@ -521,7 +537,8 @@ BEGIN
521
537
v_new_partition := @extschema@.create_single_range_partition(
522
538
@extschema@.get_schema_qualified_name(v_parent_relid),
523
539
p_value,
524
- p_range[2 ]);
540
+ p_range[2 ],
541
+ partition_name);
525
542
526
543
/* Copy data*/
527
544
v_cond := @extschema@.build_range_condition(v_attname, p_value, p_range[2 ]);
@@ -736,6 +753,10 @@ DECLARE
736
753
v_part_nameTEXT ;
737
754
738
755
BEGIN
756
+ IF @extschema@.partitions_count(parent_relid)= 0 THEN
757
+ RAISE EXCEPTION' Cannot append to empty partitions set' ;
758
+ END IF;
759
+
739
760
p_range := @extschema@.get_range_by_idx(parent_relid,- 1 ,0 );
740
761
741
762
IF @extschema@.is_date_type(p_atttype::regtype) THEN
@@ -825,6 +846,10 @@ DECLARE
825
846
v_part_nameTEXT ;
826
847
827
848
BEGIN
849
+ IF @extschema@.partitions_count(parent_relid)= 0 THEN
850
+ RAISE EXCEPTION' Cannot prepend to empty partitions set' ;
851
+ END IF;
852
+
828
853
p_range := @extschema@.get_range_by_idx(parent_relid,0 ,0 );
829
854
830
855
IF @extschema@.is_date_type(p_atttype::regtype) THEN
@@ -865,17 +890,17 @@ RETURNS TEXT AS
865
890
$$
866
891
DECLARE
867
892
v_part_nameTEXT ;
868
-
869
893
BEGIN
870
- /* check range overlap*/
871
- IF @extschema@.check_overlap(parent_relid, p_start_value, p_end_value) THEN
872
- RAISE EXCEPTION' Specified range overlaps with existing partitions' ;
873
- END IF;
874
-
875
894
IF p_start_value>= p_end_value THEN
876
895
RAISE EXCEPTION' Failed to create partition: p_start_value is greater than p_end_value' ;
877
896
END IF;
878
897
898
+ /* check range overlap*/
899
+ IF @extschema@.partitions_count(parent_relid)> 0
900
+ AND @extschema@.check_overlap(parent_relid, p_start_value, p_end_value) THEN
901
+ RAISE EXCEPTION' Specified range overlaps with existing partitions' ;
902
+ END IF;
903
+
879
904
/* Create new partition*/
880
905
v_part_name := @extschema@.create_single_range_partition(
881
906
parent_relid,