@@ -423,6 +423,10 @@ BEGIN
423
423
v_attname := attnameFROM @extschema@.pathman_config
424
424
WHERE relname::regclass= p_parent;
425
425
426
+ IF v_attname ISNULL THEN
427
+ RAISE EXCEPTION' Table % is not partitioned' , quote_ident(p_parent::TEXT );
428
+ END IF;
429
+
426
430
SELECT * INTO v_plain_schema, v_plain_relname
427
431
FROM @extschema@.get_plain_schema_and_relname(p_parent);
428
432
@@ -494,9 +498,15 @@ BEGIN
494
498
FROM pg_inherits
495
499
WHERE inhrelid= v_child_relid;
496
500
497
- SELECT attname, parttype INTO v_attname, v_part_type
501
+ SELECT attname, parttype
498
502
FROM @extschema@.pathman_config
499
- WHERE relname::regclass= v_parent_relid::regclass;
503
+ WHERE relname::regclass= v_parent_relid::regclass
504
+ INTO v_attname, v_part_type;
505
+
506
+ IF v_attname ISNULL THEN
507
+ RAISE EXCEPTION' Table % is not partitioned' ,
508
+ quote_ident(v_parent_relid::regclass::text );
509
+ END IF;
500
510
501
511
SELECT * INTO v_plain_schema, v_plain_relname
502
512
FROM @extschema@.get_plain_schema_and_relname(p_partition);
@@ -591,9 +601,15 @@ BEGIN
591
601
RAISE EXCEPTION' Cannot merge partitions having different parents' ;
592
602
END IF;
593
603
594
- SELECT attname, parttype INTO v_attname, v_part_type
604
+ SELECT attname, parttype
595
605
FROM @extschema@.pathman_config
596
- WHERE relname::regclass= v_parent_relid1::regclass;
606
+ WHERE relname::regclass= v_parent_relid1::regclass
607
+ INTO v_attname, v_part_type;
608
+
609
+ IF v_attname ISNULL THEN
610
+ RAISE EXCEPTION' Table % is not partitioned' ,
611
+ quote_ident(v_parent_relid1::regclass::text );
612
+ END IF;
597
613
598
614
/* Check if this is RANGE partition*/
599
615
IF v_part_type!= 2 THEN
@@ -637,8 +653,14 @@ DECLARE
637
653
v_child_relnameTEXT ;
638
654
v_check_nameTEXT ;
639
655
BEGIN
640
- SELECT attname INTO v_attnameFROM @extschema@.pathman_config
641
- WHERE relname::regclass= p_parent_relid::regclass;
656
+ SELECT attnameFROM @extschema@.pathman_config
657
+ WHERE relname::regclass= p_parent_relid::regclass
658
+ INTO v_attname;
659
+
660
+ IF v_attname ISNULL THEN
661
+ RAISE EXCEPTION' Table % is not partitioned' ,
662
+ quote_ident(p_parent_relid::regclass::text );
663
+ END IF;
642
664
643
665
SELECT * INTO v_plain_schema, v_plain_relname
644
666
FROM @extschema@.get_plain_schema_and_relname(p_part1);
@@ -694,16 +716,22 @@ CREATE OR REPLACE FUNCTION @extschema@.append_range_partition(
694
716
RETURNSTEXT AS
695
717
$$
696
718
DECLARE
697
- v_attnameTEXT ;
698
- v_atttypeTEXT ;
699
- v_part_nameTEXT ;
700
- v_intervalTEXT ;
719
+ v_attnameTEXT ;
720
+ v_atttypeTEXT ;
721
+ v_part_nameTEXT ;
722
+ v_intervalTEXT ;
701
723
BEGIN
702
724
/* Prevent concurrent partition creation*/
703
725
PERFORM @extschema@.acquire_partitions_lock();
704
726
705
- SELECT attname, range_interval INTO v_attname, v_interval
706
- FROM @extschema@.pathman_configWHERE relname::regclass= p_relation;
727
+ SELECT attname, range_interval
728
+ FROM @extschema@.pathman_config
729
+ WHERE relname::regclass= p_relation
730
+ INTO v_attname, v_interval;
731
+
732
+ IF v_attname ISNULL THEN
733
+ RAISE EXCEPTION' Table % is not partitioned' , quote_ident(p_relation::TEXT );
734
+ END IF;
707
735
708
736
v_atttype := @extschema@.get_attribute_type_name(p_relation, v_attname);
709
737
@@ -770,8 +798,15 @@ BEGIN
770
798
/* Prevent concurrent partition creation*/
771
799
PERFORM @extschema@.acquire_partitions_lock();
772
800
773
- SELECT attname, range_interval INTO v_attname, v_interval
774
- FROM @extschema@.pathman_configWHERE relname::regclass= p_relation;
801
+ SELECT attname, range_interval
802
+ FROM @extschema@.pathman_config
803
+ WHERE relname::regclass= p_relation
804
+ INTO v_attname, v_interval;
805
+
806
+ IF v_attname ISNULL THEN
807
+ RAISE EXCEPTION' Table % is not partitioned' , quote_ident(p_relation::TEXT );
808
+ END IF;
809
+
775
810
v_atttype := @extschema@.get_attribute_type_name(p_relation, v_attname);
776
811
777
812
EXECUTE format(' SELECT @extschema@.prepend_partition_internal($1, $2, $3, ARRAY[]::%s[])' , v_atttype)
@@ -946,7 +981,14 @@ BEGIN
946
981
, p_relation);
947
982
948
983
/* Set check constraint*/
949
- v_attname := attnameFROM @extschema@.pathman_configWHERE relname::regclass= p_relation;
984
+ v_attname := attname
985
+ FROM @extschema@.pathman_config
986
+ WHERE relname::regclass= p_relation;
987
+
988
+ IF v_attname ISNULL THEN
989
+ RAISE EXCEPTION' Table % is not partitioned' , quote_ident(p_relation::TEXT );
990
+ END IF;
991
+
950
992
v_cond := @extschema@.get_range_condition(v_attname, p_start_value, p_end_value);
951
993
952
994
/* Plain partition name and schema*/
@@ -1072,7 +1114,7 @@ $$ LANGUAGE plpgsql;
1072
1114
* Creates an update trigger
1073
1115
*/
1074
1116
CREATEOR REPLACE FUNCTION @extschema@.create_range_update_trigger(
1075
- IN relationTEXT )
1117
+ IN relationREGCLASS )
1076
1118
RETURNSTEXT AS
1077
1119
$$
1078
1120
DECLARE
@@ -1107,8 +1149,7 @@ DECLARE
1107
1149
numINTEGER := 0 ;
1108
1150
attrTEXT ;
1109
1151
BEGIN
1110
- relation := @extschema@.validate_relname(relation);
1111
- relid := relation::regclass::oid ;
1152
+ relid := relation::oid ;
1112
1153
SELECT string_agg(attname,' ,' ),
1113
1154
string_agg(' OLD.' || attname,' ,' ),
1114
1155
string_agg(' NEW.' || attname,' ,' ),
@@ -1123,7 +1164,14 @@ BEGIN
1123
1164
att_val_fmt,
1124
1165
att_fmt;
1125
1166
1126
- attr := attnameFROM @extschema@.pathman_configWHERE relname= relation;
1167
+ attr := attname
1168
+ FROM @extschema@.pathman_config
1169
+ WHERE relname::regclass= relation;
1170
+
1171
+ IF attr ISNULL THEN
1172
+ RAISE EXCEPTION' Table % is not partitioned' , quote_ident(relation::TEXT );
1173
+ END IF;
1174
+
1127
1175
EXECUTE format(func, relation, attr,0 , att_val_fmt,
1128
1176
old_fields, att_fmt, new_fields);
1129
1177
FOR recin (SELECT * FROM pg_inheritsWHERE inhparent= relation::regclass::oid )
@@ -1215,7 +1263,6 @@ CREATE OR REPLACE FUNCTION @extschema@.append_partitions_on_demand_internal(
1215
1263
RETURNSOID AS
1216
1264
$$
1217
1265
DECLARE
1218
- v_relationTEXT ;
1219
1266
v_cntINTEGER := 0 ;
1220
1267
iINTEGER := 0 ;
1221
1268
v_partTEXT ;
@@ -1227,11 +1274,16 @@ DECLARE
1227
1274
v_next_value p_new_value%TYPE;
1228
1275
v_is_dateBOOLEAN ;
1229
1276
BEGIN
1230
- v_relation := @extschema@.validate_relname(p_relid::regclass::text );
1231
-
1232
1277
/* get attribute name and interval*/
1233
- SELECT attname, range_interval INTO v_attname, v_interval
1234
- FROM @extschema@.pathman_configWHERE relname= v_relation;
1278
+ SELECT attname, range_interval
1279
+ FROM @extschema@.pathman_config
1280
+ WHERE relname::regclass= p_relid::regclass
1281
+ INTO v_attname, v_interval;
1282
+
1283
+ IF v_attname ISNULL THEN
1284
+ RAISE EXCEPTION' Table % is not partitioned' ,
1285
+ quote_ident(p_relid::regclass::text );
1286
+ END IF;
1235
1287
1236
1288
v_min := @extschema@.get_min_range_value(p_relid::regclass::oid , p_new_value);
1237
1289
v_max := @extschema@.get_max_range_value(p_relid::regclass::oid , p_new_value);