File tree Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -63,12 +63,14 @@ BEGIN
6363 EXECUTE format(' ALTER TABLE %s ADD CONSTRAINT %s
6464 CHECK (@extschema@.get_hash_part_idx(%s(%s), %s) = %s)' ,
6565 v_child_relname,
66- @extschema@.build_check_constraint_name(v_child_relname::regclass ,
66+ @extschema@.build_check_constraint_name(v_child_relname::REGCLASS ,
6767 attribute),
6868 v_hashfunc,
6969 attribute,
7070 partitions_count,
7171 partnum);
72+
73+ PERFORM @extschema@.copy_foreign_keys(parent_relid, v_child_relname::REGCLASS);
7274 END LOOP;
7375
7476 /* Notify backend about changes */
Original file line number Diff line number Diff line change @@ -546,6 +546,31 @@ $$ LANGUAGE plpgsql
546546SET pg_pathman .enable_partitionfilter = off; /* ensures that PartitionFilter is OFF */
547547
548548
549+ /*
550+ * Copy all of parent's foreign keys.
551+ */
552+ CREATE OR REPLACE FUNCTION @extschema@.copy_foreign_keys(
553+ parent_relid REGCLASS,
554+ partition REGCLASS)
555+ RETURNS VOID AS
556+ $$
557+ DECLARE
558+ rec RECORD;
559+
560+ BEGIN
561+ PERFORM @extschema@.validate_relname(parent_relid);
562+ PERFORM @extschema@.validate_relname(partition);
563+
564+ FOR rec IN (SELECT oid as conid FROM pg_catalog .pg_constraint
565+ WHERE conrelid = parent_relid AND contype = ' f' )
566+ LOOP
567+ EXECUTE format(' ALTER TABLE %s ADD %s' ,
568+ partition::TEXT ,
569+ pg_get_constraintdef(rec .conid ));
570+ END LOOP;
571+ END
572+ $$ LANGUAGE plpgsql;
573+
549574
550575/*
551576 * Create DDL trigger to call pathman_ddl_trigger_func().
Original file line number Diff line number Diff line change @@ -478,6 +478,8 @@ BEGIN
478478 p_start_value,
479479 p_end_value));
480480
481+ PERFORM @extschema@.copy_foreign_keys(parent_relid, v_child_relname::REGCLASS);
482+
481483 RETURN v_child_relname;
482484END
483485$$ LANGUAGE plpgsql
You can’t perform that action at this time.
0 commit comments