@@ -690,7 +690,7 @@ $$ LANGUAGE plpgsql;
690
690
* Append new partition
691
691
*/
692
692
CREATE OR REPLACE FUNCTION @extschema@.append_range_partition(
693
- p_relation TEXT )
693
+ p_relation REGCLASS )
694
694
RETURNS TEXT AS
695
695
$$
696
696
DECLARE
@@ -699,10 +699,8 @@ DECLARE
699
699
v_part_name TEXT ;
700
700
v_interval TEXT ;
701
701
BEGIN
702
- p_relation := @extschema@.validate_relname(p_relation);
703
-
704
702
SELECT attname, range_interval INTO v_attname, v_interval
705
- FROM @extschema@.pathman_config WHERE relname = p_relation;
703
+ FROM @extschema@.pathman_config WHERE relname::regclass = p_relation;
706
704
707
705
v_atttype := @extschema@.get_attribute_type_name(p_relation, v_attname);
708
706
@@ -714,7 +712,7 @@ BEGIN
714
712
USING p_relation, v_atttype, v_interval;
715
713
716
714
/* Invalidate cache */
717
- PERFORM @extschema@.on_update_partitions(p_relation::regclass:: oid );
715
+ PERFORM @extschema@.on_update_partitions(p_relation::oid );
718
716
719
717
/* Release lock */
720
718
PERFORM @extschema@.release_partitions_lock();
@@ -731,7 +729,7 @@ LANGUAGE plpgsql;
731
729
732
730
733
731
CREATE OR REPLACE FUNCTION @extschema@.append_partition_internal(
734
- p_relation TEXT
732
+ p_relation REGCLASS
735
733
, p_atttype TEXT
736
734
, p_interval TEXT
737
735
, p_range ANYARRAY DEFAULT NULL )
740
738
DECLARE
741
739
v_part_name TEXT ;
742
740
BEGIN
743
- p_range := @extschema@.get_range_by_idx(p_relation::regclass:: oid , - 1 , 0 );
741
+ p_range := @extschema@.get_range_by_idx(p_relation::oid , - 1 , 0 );
744
742
RAISE NOTICE ' Appending new partition...' ;
745
743
IF @extschema@.is_date(p_atttype::regtype) THEN
746
744
v_part_name := @extschema@.create_single_range_partition(p_relation
@@ -761,7 +759,7 @@ LANGUAGE plpgsql;
761
759
/*
762
760
* Prepend new partition
763
761
*/
764
- CREATE OR REPLACE FUNCTION @extschema@.prepend_range_partition(p_relation TEXT )
762
+ CREATE OR REPLACE FUNCTION @extschema@.prepend_range_partition(p_relation REGCLASS )
765
763
RETURNS TEXT AS
766
764
$$
767
765
DECLARE
@@ -770,10 +768,8 @@ DECLARE
770
768
v_part_name TEXT ;
771
769
v_interval TEXT ;
772
770
BEGIN
773
- p_relation := @extschema@.validate_relname(p_relation);
774
-
775
771
SELECT attname, range_interval INTO v_attname, v_interval
776
- FROM @extschema@.pathman_config WHERE relname = p_relation;
772
+ FROM @extschema@.pathman_config WHERE relname::regclass = p_relation;
777
773
v_atttype := @extschema@.get_attribute_type_name(p_relation, v_attname);
778
774
779
775
/* Prevent concurrent partition creation */
@@ -784,7 +780,7 @@ BEGIN
784
780
USING p_relation, v_atttype, v_interval;
785
781
786
782
/* Invalidate cache */
787
- PERFORM @extschema@.on_update_partitions(p_relation::regclass:: oid );
783
+ PERFORM @extschema@.on_update_partitions(p_relation::oid );
788
784
789
785
/* Release lock */
790
786
PERFORM @extschema@.release_partitions_lock();
@@ -801,7 +797,7 @@ LANGUAGE plpgsql;
801
797
802
798
803
799
CREATE OR REPLACE FUNCTION @extschema@.prepend_partition_internal(
804
- p_relation TEXT
800
+ p_relation REGCLASS
805
801
, p_atttype TEXT
806
802
, p_interval TEXT
807
803
, p_range ANYARRAY DEFAULT NULL )
810
806
DECLARE
811
807
v_part_name TEXT ;
812
808
BEGIN
813
- p_range := @extschema@.get_range_by_idx(p_relation::regclass:: oid , 0 , 0 );
809
+ p_range := @extschema@.get_range_by_idx(p_relation::oid , 0 , 0 );
814
810
RAISE NOTICE ' Prepending new partition...' ;
815
811
816
812
IF @extschema@.is_date(p_atttype::regtype) THEN
817
813
v_part_name := @extschema@.create_single_range_partition(p_relation
818
814
, p_range[1 ] - p_interval::interval
819
815
, p_range[1 ]);
820
816
ELSE
821
- EXECUTE format(' SELECT @extschema@.create_single_range_partition($1, $2, $2 - $3::%s)' , p_atttype)
817
+ EXECUTE format(' SELECT @extschema@.create_single_range_partition($1, $2 - $3::%s, $2 )' , p_atttype)
822
818
USING p_relation, p_range[1 ], p_interval
823
819
INTO v_part_name;
824
820
END IF;
@@ -833,7 +829,7 @@ LANGUAGE plpgsql;
833
829
* Add new partition
834
830
*/
835
831
CREATE OR REPLACE FUNCTION @extschema@.add_range_partition(
836
- p_relation TEXT
832
+ p_relation REGCLASS
837
833
, p_start_value ANYELEMENT
838
834
, p_end_value ANYELEMENT)
839
835
RETURNS TEXT AS
@@ -844,10 +840,8 @@ BEGIN
844
840
/* Prevent concurrent partition creation */
845
841
PERFORM @extschema@.acquire_partitions_lock();
846
842
847
- p_relation := @extschema@.validate_relname(p_relation);
848
-
849
843
/* check range overlap */
850
- IF @extschema@.check_overlap(p_relation::regclass:: oid , p_start_value, p_end_value) != FALSE THEN
844
+ IF @extschema@.check_overlap(p_relation::oid , p_start_value, p_end_value) != FALSE THEN
851
845
RAISE EXCEPTION ' Specified range overlaps with existing partitions' ;
852
846
END IF;
853
847
@@ -857,7 +851,7 @@ BEGIN
857
851
858
852
/* Create new partition */
859
853
v_part_name := @extschema@.create_single_range_partition(p_relation, p_start_value, p_end_value);
860
- PERFORM @extschema@.on_update_partitions(p_relation::regclass:: oid );
854
+ PERFORM @extschema@.on_update_partitions(p_relation::oid );
861
855
862
856
/* Release lock */
863
857
PERFORM @extschema@.release_partitions_lock();
@@ -917,26 +911,27 @@ LANGUAGE plpgsql;
917
911
* Attach range partition
918
912
*/
919
913
CREATE OR REPLACE FUNCTION @extschema@.attach_range_partition(
920
- p_relation TEXT
921
- , p_partition TEXT
922
- , p_start_value ANYELEMENT
923
- , p_end_value ANYELEMENT)
914
+ p_relation REGCLASS
915
+ , p_partition REGCLASS
916
+ , p_start_value ANYELEMENT
917
+ , p_end_value ANYELEMENT)
924
918
RETURNS TEXT AS
925
919
$$
926
920
DECLARE
927
- v_attname TEXT ;
928
- v_cond TEXT ;
921
+ v_attname TEXT ;
922
+ v_cond TEXT ;
923
+ v_plain_partname TEXT ;
924
+ v_plain_schema TEXT ;
929
925
BEGIN
930
926
/* Prevent concurrent partition management */
931
927
PERFORM @extschema@.acquire_partitions_lock();
932
928
933
- p_relation := @extschema@.validate_relname(p_relation);
934
929
935
- IF @extschema@.check_overlap(p_relation::regclass:: oid , p_start_value, p_end_value) != FALSE THEN
930
+ IF @extschema@.check_overlap(p_relation::oid , p_start_value, p_end_value) != FALSE THEN
936
931
RAISE EXCEPTION ' Specified range overlaps with existing partitions' ;
937
932
END IF;
938
933
939
- IF NOT @extschema@.validate_relations_equality(p_relation::regclass , p_partition::regclass ) THEN
934
+ IF NOT @extschema@.validate_relations_equality(p_relation, p_partition) THEN
940
935
RAISE EXCEPTION ' Partition must have the exact same structure as parent' ;
941
936
END IF;
942
937
@@ -946,15 +941,19 @@ BEGIN
946
941
, p_relation);
947
942
948
943
/* Set check constraint */
949
- v_attname := attname FROM @extschema@.pathman_config WHERE relname = p_relation;
944
+ v_attname := attname FROM @extschema@.pathman_config WHERE relname::regclass = p_relation;
950
945
v_cond := @extschema@.get_range_condition(v_attname, p_start_value, p_end_value);
951
- EXECUTE format(' ALTER TABLE %s ADD CONSTRAINT %s_check CHECK (%s)'
946
+
947
+ /* Plain partition name and schema */
948
+ SELECT * INTO v_plain_schema, v_plain_partname FROM @extschema@.get_plain_schema_and_relname(p_partition);
949
+
950
+ EXECUTE format(' ALTER TABLE %s ADD CONSTRAINT %s CHECK (%s)'
952
951
, p_partition
953
- , @extschema@.get_schema_qualified_name(p_partition::regclass )
952
+ , v_plain_schema || ' _ ' || quote_ident(v_plain_partname || ' _check ' )
954
953
, v_cond);
955
954
956
955
/* Invalidate cache */
957
- PERFORM @extschema@.on_update_partitions(p_relation::regclass:: oid );
956
+ PERFORM @extschema@.on_update_partitions(p_relation::oid );
958
957
959
958
/* Release lock */
960
959
PERFORM @extschema@.release_partitions_lock();
0 commit comments