5959p_attribute := lower (p_attribute);
6060PERFORM @extschema@.common_relation_checks(parent_relid, p_attribute);
6161
62+ IF p_count< 0 THEN
63+ RAISE EXCEPTION' Partitions count must not be less than zero' ;
64+ END IF;
65+
6266/* Try to determine partitions count if not set*/
6367IF p_count ISNULL THEN
6468EXECUTE format(' SELECT count(*), max(%s) FROM %s' , p_attribute, parent_relid)
@@ -76,13 +80,19 @@ BEGIN
7680END LOOP;
7781END IF;
7882
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;
8696
8797SELECT * INTO v_plain_schema, v_plain_relname
8898FROM @extschema@.get_plain_schema_and_relname(parent_relid);
@@ -147,8 +157,8 @@ BEGIN
147157p_attribute := lower (p_attribute);
148158PERFORM @extschema@.common_relation_checks(parent_relid, p_attribute);
149159
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' ;
152162END IF;
153163
154164/* Try to determine partitions count if not set*/
@@ -172,11 +182,17 @@ BEGIN
172182END LOOP;
173183END IF;
174184
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;
180196
181197SELECT * INTO v_plain_schema, v_plain_relname
182198FROM @extschema@.get_plain_schema_and_relname(parent_relid);
@@ -521,7 +537,8 @@ BEGIN
521537v_new_partition := @extschema@.create_single_range_partition(
522538@extschema@.get_schema_qualified_name(v_parent_relid),
523539p_value,
524- p_range[2 ]);
540+ p_range[2 ],
541+ partition_name);
525542
526543/* Copy data*/
527544v_cond := @extschema@.build_range_condition(v_attname, p_value, p_range[2 ]);
@@ -736,6 +753,10 @@ DECLARE
736753v_part_nameTEXT ;
737754
738755BEGIN
756+ IF @extschema@.partitions_count(parent_relid)= 0 THEN
757+ RAISE EXCEPTION' Cannot append to empty partitions set' ;
758+ END IF;
759+
739760p_range := @extschema@.get_range_by_idx(parent_relid,- 1 ,0 );
740761
741762IF @extschema@.is_date_type(p_atttype::regtype) THEN
@@ -825,6 +846,10 @@ DECLARE
825846v_part_nameTEXT ;
826847
827848BEGIN
849+ IF @extschema@.partitions_count(parent_relid)= 0 THEN
850+ RAISE EXCEPTION' Cannot prepend to empty partitions set' ;
851+ END IF;
852+
828853p_range := @extschema@.get_range_by_idx(parent_relid,0 ,0 );
829854
830855IF @extschema@.is_date_type(p_atttype::regtype) THEN
@@ -865,17 +890,17 @@ RETURNS TEXT AS
865890$$
866891DECLARE
867892v_part_nameTEXT ;
868-
869893BEGIN
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-
875894IF p_start_value>= p_end_value THEN
876895RAISE EXCEPTION' Failed to create partition: p_start_value is greater than p_end_value' ;
877896END IF;
878897
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+
879904/* Create new partition*/
880905v_part_name := @extschema@.create_single_range_partition(
881906parent_relid,