@@ -417,6 +417,10 @@ BEGIN
417
417
v_attname := attnameFROM @extschema@.pathman_config
418
418
WHERE relname::regclass= p_parent;
419
419
420
+ IF v_attname ISNULL THEN
421
+ RAISE EXCEPTION' Table % is not partitioned' , quote_ident(p_parent::TEXT );
422
+ END IF;
423
+
420
424
SELECT * INTO v_plain_schema, v_plain_relname
421
425
FROM @extschema@.get_plain_schema_and_relname(p_parent);
422
426
@@ -488,9 +492,15 @@ BEGIN
488
492
FROM pg_inherits
489
493
WHERE inhrelid= v_child_relid;
490
494
491
- SELECT attname, parttype INTO v_attname, v_part_type
495
+ SELECT attname, parttype
492
496
FROM @extschema@.pathman_config
493
- WHERE relname::regclass= v_parent_relid::regclass;
497
+ WHERE relname::regclass= v_parent_relid::regclass
498
+ INTO v_attname, v_part_type;
499
+
500
+ IF v_attname ISNULL THEN
501
+ RAISE EXCEPTION' Table % is not partitioned' ,
502
+ quote_ident(v_parent_relid::regclass::text );
503
+ END IF;
494
504
495
505
SELECT * INTO v_plain_schema, v_plain_relname
496
506
FROM @extschema@.get_plain_schema_and_relname(p_partition);
@@ -585,9 +595,15 @@ BEGIN
585
595
RAISE EXCEPTION' Cannot merge partitions having different parents' ;
586
596
END IF;
587
597
588
- SELECT attname, parttype INTO v_attname, v_part_type
598
+ SELECT attname, parttype
589
599
FROM @extschema@.pathman_config
590
- WHERE relname::regclass= v_parent_relid1::regclass;
600
+ WHERE relname::regclass= v_parent_relid1::regclass
601
+ INTO v_attname, v_part_type;
602
+
603
+ IF v_attname ISNULL THEN
604
+ RAISE EXCEPTION' Table % is not partitioned' ,
605
+ quote_ident(v_parent_relid1::regclass::text );
606
+ END IF;
591
607
592
608
/* Check if this is RANGE partition*/
593
609
IF v_part_type!= 2 THEN
@@ -631,8 +647,14 @@ DECLARE
631
647
v_child_relnameTEXT ;
632
648
v_check_nameTEXT ;
633
649
BEGIN
634
- SELECT attname INTO v_attnameFROM @extschema@.pathman_config
635
- WHERE relname::regclass= p_parent_relid::regclass;
650
+ SELECT attnameFROM @extschema@.pathman_config
651
+ WHERE relname::regclass= p_parent_relid::regclass
652
+ INTO v_attname;
653
+
654
+ IF v_attname ISNULL THEN
655
+ RAISE EXCEPTION' Table % is not partitioned' ,
656
+ quote_ident(p_parent_relid::regclass::text );
657
+ END IF;
636
658
637
659
SELECT * INTO v_plain_schema, v_plain_relname
638
660
FROM @extschema@.get_plain_schema_and_relname(p_part1);
@@ -688,16 +710,22 @@ CREATE OR REPLACE FUNCTION @extschema@.append_range_partition(
688
710
RETURNSTEXT AS
689
711
$$
690
712
DECLARE
691
- v_attnameTEXT ;
692
- v_atttypeTEXT ;
693
- v_part_nameTEXT ;
694
- v_intervalTEXT ;
713
+ v_attnameTEXT ;
714
+ v_atttypeTEXT ;
715
+ v_part_nameTEXT ;
716
+ v_intervalTEXT ;
695
717
BEGIN
696
718
/* Prevent concurrent partition creation*/
697
719
PERFORM @extschema@.acquire_partitions_lock();
698
720
699
- SELECT attname, range_interval INTO v_attname, v_interval
700
- FROM @extschema@.pathman_configWHERE relname::regclass= p_relation;
721
+ SELECT attname, range_interval
722
+ FROM @extschema@.pathman_config
723
+ WHERE relname::regclass= p_relation
724
+ INTO v_attname, v_interval;
725
+
726
+ IF v_attname ISNULL THEN
727
+ RAISE EXCEPTION' Table % is not partitioned' , quote_ident(p_relation::TEXT );
728
+ END IF;
701
729
702
730
v_atttype := @extschema@.get_attribute_type_name(p_relation, v_attname);
703
731
@@ -764,8 +792,15 @@ BEGIN
764
792
/* Prevent concurrent partition creation*/
765
793
PERFORM @extschema@.acquire_partitions_lock();
766
794
767
- SELECT attname, range_interval INTO v_attname, v_interval
768
- FROM @extschema@.pathman_configWHERE relname::regclass= p_relation;
795
+ SELECT attname, range_interval
796
+ FROM @extschema@.pathman_config
797
+ WHERE relname::regclass= p_relation
798
+ INTO v_attname, v_interval;
799
+
800
+ IF v_attname ISNULL THEN
801
+ RAISE EXCEPTION' Table % is not partitioned' , quote_ident(p_relation::TEXT );
802
+ END IF;
803
+
769
804
v_atttype := @extschema@.get_attribute_type_name(p_relation, v_attname);
770
805
771
806
EXECUTE format(' SELECT @extschema@.prepend_partition_internal($1, $2, $3, ARRAY[]::%s[])' , v_atttype)
@@ -940,7 +975,14 @@ BEGIN
940
975
, p_relation);
941
976
942
977
/* Set check constraint*/
943
- v_attname := attnameFROM @extschema@.pathman_configWHERE relname::regclass= p_relation;
978
+ v_attname := attname
979
+ FROM @extschema@.pathman_config
980
+ WHERE relname::regclass= p_relation;
981
+
982
+ IF v_attname ISNULL THEN
983
+ RAISE EXCEPTION' Table % is not partitioned' , quote_ident(p_relation::TEXT );
984
+ END IF;
985
+
944
986
v_cond := @extschema@.get_range_condition(v_attname, p_start_value, p_end_value);
945
987
946
988
/* Plain partition name and schema*/
@@ -1010,7 +1052,7 @@ LANGUAGE plpgsql;
1010
1052
* Creates an update trigger
1011
1053
*/
1012
1054
CREATEOR REPLACE FUNCTION @extschema@.create_range_update_trigger(
1013
- IN relationTEXT )
1055
+ IN relationREGCLASS )
1014
1056
RETURNSTEXT AS
1015
1057
$$
1016
1058
DECLARE
@@ -1045,8 +1087,7 @@ DECLARE
1045
1087
numINTEGER := 0 ;
1046
1088
attrTEXT ;
1047
1089
BEGIN
1048
- relation := @extschema@.validate_relname(relation);
1049
- relid := relation::regclass::oid ;
1090
+ relid := relation::oid ;
1050
1091
SELECT string_agg(attname,' ,' ),
1051
1092
string_agg(' OLD.' || attname,' ,' ),
1052
1093
string_agg(' NEW.' || attname,' ,' ),
@@ -1061,7 +1102,14 @@ BEGIN
1061
1102
att_val_fmt,
1062
1103
att_fmt;
1063
1104
1064
- attr := attnameFROM @extschema@.pathman_configWHERE relname= relation;
1105
+ attr := attname
1106
+ FROM @extschema@.pathman_config
1107
+ WHERE relname::regclass= relation;
1108
+
1109
+ IF attr ISNULL THEN
1110
+ RAISE EXCEPTION' Table % is not partitioned' , quote_ident(relation::TEXT );
1111
+ END IF;
1112
+
1065
1113
EXECUTE format(func, relation, attr,0 , att_val_fmt,
1066
1114
old_fields, att_fmt, new_fields);
1067
1115
FOR recin (SELECT * FROM pg_inheritsWHERE inhparent= relation::regclass::oid )
@@ -1087,7 +1135,6 @@ CREATE OR REPLACE FUNCTION @extschema@.append_partitions_on_demand_internal(
1087
1135
RETURNSOID AS
1088
1136
$$
1089
1137
DECLARE
1090
- v_relationTEXT ;
1091
1138
v_cntINTEGER := 0 ;
1092
1139
iINTEGER := 0 ;
1093
1140
v_partTEXT ;
@@ -1099,11 +1146,16 @@ DECLARE
1099
1146
v_next_value p_new_value%TYPE;
1100
1147
v_is_dateBOOLEAN ;
1101
1148
BEGIN
1102
- v_relation := @extschema@.validate_relname(p_relid::regclass::text );
1103
-
1104
1149
/* get attribute name and interval*/
1105
- SELECT attname, range_interval INTO v_attname, v_interval
1106
- FROM @extschema@.pathman_configWHERE relname= v_relation;
1150
+ SELECT attname, range_interval
1151
+ FROM @extschema@.pathman_config
1152
+ WHERE relname::regclass= p_relid::regclass
1153
+ INTO v_attname, v_interval;
1154
+
1155
+ IF v_attname ISNULL THEN
1156
+ RAISE EXCEPTION' Table % is not partitioned' ,
1157
+ quote_ident(p_relid::regclass::text );
1158
+ END IF;
1107
1159
1108
1160
v_min := @extschema@.get_min_range_value(p_relid::regclass::oid , p_new_value);
1109
1161
v_max := @extschema@.get_max_range_value(p_relid::regclass::oid , p_new_value);