60
60
END
61
61
$$ LANGUAGE plpgsql;
62
62
63
+
64
+ CREATEOR REPLACE FUNCTION @extschema@.prepare_for_partitioning(
65
+ parent_relidREGCLASS,
66
+ attributeTEXT ,
67
+ partition_dataBOOLEAN )
68
+ RETURNS VOIDAS
69
+ $$
70
+ BEGIN
71
+ PERFORM @extschema@.validate_relname(parent_relid);
72
+
73
+ IF partition_data= true THEN
74
+ /* Acquire data modification lock*/
75
+ PERFORM @extschema@.prevent_relation_modification(parent_relid);
76
+ ELSE
77
+ /* Acquire lock on parent*/
78
+ PERFORM @extschema@.lock_partitioned_relation(parent_relid);
79
+ END IF;
80
+
81
+ attribute := lower (attribute);
82
+ PERFORM @extschema@.common_relation_checks(parent_relid, attribute);
83
+ END
84
+ $$ LANGUAGE plpgsql;
85
+
63
86
/*
64
87
* Creates RANGE partitions for specified relation based on datetime attribute
65
88
*/
@@ -81,18 +104,8 @@ DECLARE
81
104
iINTEGER ;
82
105
83
106
BEGIN
84
- PERFORM @extschema@.validate_relname(parent_relid);
85
-
86
- IF partition_data= true THEN
87
- /* Acquire data modification lock*/
88
- PERFORM @extschema@.prevent_relation_modification(parent_relid);
89
- ELSE
90
- /* Acquire lock on parent*/
91
- PERFORM @extschema@.lock_partitioned_relation(parent_relid);
92
- END IF;
93
-
94
107
attribute := lower (attribute);
95
- PERFORM @extschema@.common_relation_checks (parent_relid, attribute);
108
+ PERFORM @extschema@.prepare_for_partitioning (parent_relid, attribute, partition_data );
96
109
97
110
IF p_count< 0 THEN
98
111
RAISE EXCEPTION' "p_count" must not be less than 0' ;
@@ -196,18 +209,8 @@ DECLARE
196
209
iINTEGER ;
197
210
198
211
BEGIN
199
- PERFORM @extschema@.validate_relname(parent_relid);
200
-
201
- IF partition_data= true THEN
202
- /* Acquire data modification lock*/
203
- PERFORM @extschema@.prevent_relation_modification(parent_relid);
204
- ELSE
205
- /* Acquire lock on parent*/
206
- PERFORM @extschema@.lock_partitioned_relation(parent_relid);
207
- END IF;
208
-
209
212
attribute := lower (attribute);
210
- PERFORM @extschema@.common_relation_checks (parent_relid, attribute);
213
+ PERFORM @extschema@.prepare_for_partitioning (parent_relid, attribute, partition_data );
211
214
212
215
IF p_count< 0 THEN
213
216
RAISE EXCEPTION' partitions count must not be less than zero' ;
@@ -304,18 +307,8 @@ DECLARE
304
307
part_countINTEGER := 0 ;
305
308
306
309
BEGIN
307
- PERFORM @extschema@.validate_relname(parent_relid);
308
-
309
- IF partition_data= true THEN
310
- /* Acquire data modification lock*/
311
- PERFORM @extschema@.prevent_relation_modification(parent_relid);
312
- ELSE
313
- /* Acquire lock on parent*/
314
- PERFORM @extschema@.lock_partitioned_relation(parent_relid);
315
- END IF;
316
-
317
310
attribute := lower (attribute);
318
- PERFORM @extschema@.common_relation_checks (parent_relid, attribute);
311
+ PERFORM @extschema@.prepare_for_partitioning (parent_relid, attribute, partition_data );
319
312
320
313
/* Check boundaries*/
321
314
PERFORM @extschema@.check_boundaries(parent_relid,
@@ -374,18 +367,8 @@ DECLARE
374
367
part_countINTEGER := 0 ;
375
368
376
369
BEGIN
377
- PERFORM @extschema@.validate_relname(parent_relid);
378
-
379
- IF partition_data= true THEN
380
- /* Acquire data modification lock*/
381
- PERFORM @extschema@.prevent_relation_modification(parent_relid);
382
- ELSE
383
- /* Acquire lock on parent*/
384
- PERFORM @extschema@.lock_partitioned_relation(parent_relid);
385
- END IF;
386
-
387
370
attribute := lower (attribute);
388
- PERFORM @extschema@.common_relation_checks (parent_relid, attribute);
371
+ PERFORM @extschema@.prepare_for_partitioning (parent_relid, attribute, partition_data );
389
372
390
373
/* Check boundaries*/
391
374
PERFORM @extschema@.check_boundaries(parent_relid,
@@ -435,7 +418,10 @@ $$ LANGUAGE plpgsql;
435
418
CREATEOR REPLACE FUNCTION @extschema@.create_range_partitions2(
436
419
parent_relidREGCLASS,
437
420
attributeTEXT ,
438
- boundsANYARRAY)
421
+ boundsANYARRAY,
422
+ relnamesTEXT [] DEFAULTNULL ,
423
+ tablespacesTEXT [] DEFAULTNULL ,
424
+ partition_dataBOOLEAN DEFAULT TRUE)
439
425
RETURNSINTEGER AS
440
426
$$
441
427
DECLARE
@@ -449,18 +435,8 @@ BEGIN
449
435
RAISE EXCEPTION' Bounds array must have at least two values' ;
450
436
END IF;
451
437
452
- PERFORM @extschema@.validate_relname(parent_relid);
453
-
454
- IF partition_data= true THEN
455
- /* Acquire data modification lock*/
456
- PERFORM @extschema@.prevent_relation_modification(parent_relid);
457
- ELSE
458
- /* Acquire lock on parent*/
459
- PERFORM @extschema@.lock_partitioned_relation(parent_relid);
460
- END IF;
461
-
462
438
attribute := lower (attribute);
463
- PERFORM @extschema@.common_relation_checks (parent_relid, attribute);
439
+ PERFORM @extschema@.prepare_for_partitioning (parent_relid, attribute, partition_data );
464
440
465
441
/* Check boundaries*/
466
442
PERFORM @extschema@.check_boundaries(parent_relid,
@@ -476,7 +452,10 @@ BEGIN
476
452
FROM @extschema@.get_plain_schema_and_relname(parent_relid);
477
453
478
454
/* Create partitions*/
479
- part_count := @extschema@.create_range_partitions_internal(parent_relid, bounds);
455
+ part_count := @extschema@.create_range_partitions_internal(parent_relid,
456
+ bounds,
457
+ relnames,
458
+ tablespaces);
480
459
481
460
/* Notify backend about changes*/
482
461
PERFORM @extschema@.on_create_partitions(parent_relid);
@@ -489,15 +468,17 @@ BEGIN
489
468
PERFORM @extschema@.set_enable_parent(parent_relid, true);
490
469
END IF;
491
470
492
- RETURN0 ;
471
+ RETURNpart_count ;
493
472
END
494
473
$$
495
474
LANGUAGE plpgsql;
496
475
497
476
498
477
CREATEOR REPLACE FUNCTION @extschema@.create_range_partitions_internal(
499
478
parent_relidREGCLASS,
500
- valueANYARRAY)
479
+ boundsANYARRAY,
480
+ relnamesTEXT [],
481
+ tablespacesTEXT [])
501
482
RETURNS REGCLASSAS ' pg_pathman' ,' create_range_partitions_internal'
502
483
LANGUAGE C;
503
484
@@ -640,7 +621,8 @@ BEGIN
640
621
641
622
v_atttype := @extschema@.get_partition_key_type(parent_relid);
642
623
643
- IF NOT @extschema@.is_operator_supported(v_atttype,' +' ) THEN
624
+ IF NOT @extschema@.is_date_type(v_atttype)AND
625
+ NOT @extschema@.is_operator_supported(v_atttype,' +' ) THEN
644
626
RAISE EXCEPTION' Type % doesn' ' t support' ' +' ' operator' , v_atttype::regtype;
645
627
END IF;
646
628
@@ -749,7 +731,8 @@ BEGIN
749
731
750
732
v_atttype := @extschema@.get_partition_key_type(parent_relid);
751
733
752
- IF NOT @extschema@.is_operator_supported(v_atttype,' -' ) THEN
734
+ IF NOT @extschema@.is_date_type(v_atttype)AND
735
+ NOT @extschema@.is_operator_supported(v_atttype,' -' ) THEN
753
736
RAISE EXCEPTION' Type % doesn' ' t support' ' -' ' operator' , v_atttype::regtype;
754
737
END IF;
755
738