@@ -581,23 +581,22 @@ DECLARE
581581v_recRECORD;
582582v_rowsBIGINT ;
583583v_part_countINTEGER := 0 ;
584- conf_num_del INTEGER ;
584+ conf_num INTEGER ;
585585v_relkindCHAR ;
586586
587587BEGIN
588588PERFORM @extschema@.validate_relname(parent_relid);
589589
590- /* Drop trigger first */
591- PERFORM @extschema@.drop_triggers (parent_relid);
590+ /* Acquire data modification lock */
591+ PERFORM @extschema@.prevent_relation_modification (parent_relid);
592592
593- WITH config_num_deletedAS (DELETE FROM @extschema@.pathman_config
594- WHERE partrel= parent_relid
595- RETURNING* )
596- SELECT count (* )from config_num_deleted INTO conf_num_del;
593+ /* First, drop all triggers*/
594+ PERFORM @extschema@.drop_triggers(parent_relid);
597595
598- DELETE FROM @extschema@.pathman_config_paramsWHERE partrel= parent_relid;
596+ SELECT count (* )FROM @extschema@.pathman_config
597+ WHERE partrel= parent_relid INTO conf_num;
599598
600- IFconf_num_del = 0 THEN
599+ IFconf_num = 0 THEN
601600RAISE EXCEPTION' relation "%" has no partitions' , parent_relid::TEXT ;
602601END IF;
603602
@@ -621,8 +620,8 @@ BEGIN
621620INTO v_relkind;
622621
623622/*
624- * Determine the kind of child relation. It can be either regular
625- * table (r) or foreign table (f). Depending on relkind we use
623+ * Determine the kind of child relation. It can be eithera regular
624+ * table (r) ora foreign table (f). Depending on relkind we use
626625 * DROP TABLE or DROP FOREIGN TABLE.
627626*/
628627IF v_relkind= ' f' THEN
@@ -634,6 +633,10 @@ BEGIN
634633v_part_count := v_part_count+ 1 ;
635634END LOOP;
636635
636+ /* Finally delete both config entries*/
637+ DELETE FROM @extschema@.pathman_configWHERE partrel= parent_relid;
638+ DELETE FROM @extschema@.pathman_config_paramsWHERE partrel= parent_relid;
639+
637640RETURN v_part_count;
638641END
639642$$ LANGUAGE plpgsql