@@ -690,7 +690,7 @@ $$ LANGUAGE plpgsql;
690690 * Append new partition
691691*/
692692CREATEOR REPLACE FUNCTION @extschema@.append_range_partition(
693- p_relationTEXT )
693+ p_relationREGCLASS )
694694RETURNSTEXT AS
695695$$
696696DECLARE
@@ -699,10 +699,8 @@ DECLARE
699699v_part_nameTEXT ;
700700v_intervalTEXT ;
701701BEGIN
702- p_relation := @extschema@.validate_relname(p_relation);
703-
704702SELECT attname, range_interval INTO v_attname, v_interval
705- FROM @extschema@.pathman_configWHERE relname= p_relation;
703+ FROM @extschema@.pathman_configWHERE relname::regclass = p_relation;
706704
707705v_atttype := @extschema@.get_attribute_type_name(p_relation, v_attname);
708706
@@ -714,7 +712,7 @@ BEGIN
714712USING p_relation, v_atttype, v_interval;
715713
716714/* Invalidate cache*/
717- PERFORM @extschema@.on_update_partitions(p_relation::regclass:: oid );
715+ PERFORM @extschema@.on_update_partitions(p_relation::oid );
718716
719717/* Release lock*/
720718PERFORM @extschema@.release_partitions_lock();
@@ -731,7 +729,7 @@ LANGUAGE plpgsql;
731729
732730
733731CREATEOR REPLACE FUNCTION @extschema@.append_partition_internal(
734- p_relationTEXT
732+ p_relationREGCLASS
735733, p_atttypeTEXT
736734, p_intervalTEXT
737735, p_range ANYARRAY DEFAULTNULL )
740738DECLARE
741739v_part_nameTEXT ;
742740BEGIN
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 );
744742RAISE NOTICE' Appending new partition...' ;
745743IF @extschema@.is_date(p_atttype::regtype) THEN
746744v_part_name := @extschema@.create_single_range_partition(p_relation
@@ -761,7 +759,7 @@ LANGUAGE plpgsql;
761759/*
762760 * Prepend new partition
763761*/
764- CREATEOR REPLACE FUNCTION @extschema@.prepend_range_partition(p_relationTEXT )
762+ CREATEOR REPLACE FUNCTION @extschema@.prepend_range_partition(p_relationREGCLASS )
765763RETURNSTEXT AS
766764$$
767765DECLARE
@@ -770,10 +768,8 @@ DECLARE
770768v_part_nameTEXT ;
771769v_intervalTEXT ;
772770BEGIN
773- p_relation := @extschema@.validate_relname(p_relation);
774-
775771SELECT attname, range_interval INTO v_attname, v_interval
776- FROM @extschema@.pathman_configWHERE relname= p_relation;
772+ FROM @extschema@.pathman_configWHERE relname::regclass = p_relation;
777773v_atttype := @extschema@.get_attribute_type_name(p_relation, v_attname);
778774
779775/* Prevent concurrent partition creation*/
@@ -784,7 +780,7 @@ BEGIN
784780USING p_relation, v_atttype, v_interval;
785781
786782/* Invalidate cache*/
787- PERFORM @extschema@.on_update_partitions(p_relation::regclass:: oid );
783+ PERFORM @extschema@.on_update_partitions(p_relation::oid );
788784
789785/* Release lock*/
790786PERFORM @extschema@.release_partitions_lock();
@@ -801,7 +797,7 @@ LANGUAGE plpgsql;
801797
802798
803799CREATEOR REPLACE FUNCTION @extschema@.prepend_partition_internal(
804- p_relationTEXT
800+ p_relationREGCLASS
805801, p_atttypeTEXT
806802, p_intervalTEXT
807803, p_range ANYARRAY DEFAULTNULL )
810806DECLARE
811807v_part_nameTEXT ;
812808BEGIN
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 );
814810RAISE NOTICE' Prepending new partition...' ;
815811
816812IF @extschema@.is_date(p_atttype::regtype) THEN
817813v_part_name := @extschema@.create_single_range_partition(p_relation
818814 , p_range[1 ]- p_interval::interval
819815 , p_range[1 ]);
820816ELSE
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)
822818USING p_relation, p_range[1 ], p_interval
823819INTO v_part_name;
824820END IF;
@@ -833,7 +829,7 @@ LANGUAGE plpgsql;
833829 * Add new partition
834830*/
835831CREATEOR REPLACE FUNCTION @extschema@.add_range_partition(
836- p_relationTEXT
832+ p_relationREGCLASS
837833, p_start_value ANYELEMENT
838834, p_end_value ANYELEMENT)
839835RETURNSTEXT AS
@@ -844,10 +840,8 @@ BEGIN
844840/* Prevent concurrent partition creation*/
845841PERFORM @extschema@.acquire_partitions_lock();
846842
847- p_relation := @extschema@.validate_relname(p_relation);
848-
849843/* 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
851845RAISE EXCEPTION' Specified range overlaps with existing partitions' ;
852846END IF;
853847
@@ -857,7 +851,7 @@ BEGIN
857851
858852/* Create new partition*/
859853v_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 );
861855
862856/* Release lock*/
863857PERFORM @extschema@.release_partitions_lock();
@@ -917,26 +911,28 @@ LANGUAGE plpgsql;
917911 * Attach range partition
918912*/
919913CREATEOR REPLACE FUNCTION @extschema@.attach_range_partition(
920- p_relationTEXT
921- , p_partitionTEXT
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)
924918RETURNSTEXT AS
925919$$
926920DECLARE
927- v_attnameTEXT ;
928- v_condTEXT ;
921+ v_attnameTEXT ;
922+ v_condTEXT ;
923+ v_plain_partnameTEXT ;
924+ v_plain_schemaTEXT ;
929925BEGIN
930926/* Prevent concurrent partition management*/
931927PERFORM @extschema@.acquire_partitions_lock();
932928
933- p_relation := @extschema@.validate_relname(p_relation);
929+ -- p_relation := @extschema@.validate_relname(p_relation);
934930
935- IF @extschema@.check_overlap(p_relation::regclass:: oid , p_start_value, p_end_value)!= FALSE THEN
931+ IF @extschema@.check_overlap(p_relation::oid , p_start_value, p_end_value)!= FALSE THEN
936932RAISE EXCEPTION' Specified range overlaps with existing partitions' ;
937933END IF;
938934
939- IF NOT @extschema@.validate_relations_equality(p_relation::regclass , p_partition::regclass ) THEN
935+ IF NOT @extschema@.validate_relations_equality(p_relation, p_partition) THEN
940936 RAISE EXCEPTION' Partition must have the exact same structure as parent' ;
941937 END IF;
942938
@@ -946,15 +942,19 @@ BEGIN
946942 , p_relation);
947943
948944/* Set check constraint*/
949- v_attname := attnameFROM @extschema@.pathman_configWHERE relname= p_relation;
945+ v_attname := attnameFROM @extschema@.pathman_configWHERE relname::regclass = p_relation;
950946v_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)'
947+
948+ /* Plain partition name and schema*/
949+ SELECT * INTO v_plain_schema, v_plain_partnameFROM @extschema@.get_plain_schema_and_relname(p_partition);
950+
951+ EXECUTE format(' ALTER TABLE %s ADD CONSTRAINT %s CHECK (%s)'
952952 , p_partition
953- ,@extschema@.get_schema_qualified_name(p_partition::regclass )
953+ ,v_plain_schema || ' _ ' || quote_ident(v_plain_partname || ' _check ' )
954954 , v_cond);
955955
956956/* Invalidate cache*/
957- PERFORM @extschema@.on_update_partitions(p_relation::regclass:: oid );
957+ PERFORM @extschema@.on_update_partitions(p_relation::oid );
958958
959959/* Release lock*/
960960PERFORM @extschema@.release_partitions_lock();