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
63
63
EXECUTE format(' ALTER TABLE %s ADD CONSTRAINT %s
64
64
CHECK (@extschema@.get_hash_part_idx(%s(%s), %s) = %s)' ,
65
65
v_child_relname,
66
- @extschema@.build_check_constraint_name(v_child_relname::regclass ,
66
+ @extschema@.build_check_constraint_name(v_child_relname::REGCLASS ,
67
67
attribute),
68
68
v_hashfunc,
69
69
attribute,
70
70
partitions_count,
71
71
partnum);
72
+
73
+ PERFORM @extschema@.copy_foreign_keys(parent_relid, v_child_relname::REGCLASS);
72
74
END LOOP;
73
75
74
76
/* Notify backend about changes */
Original file line number Diff line number Diff line change @@ -546,6 +546,31 @@ $$ LANGUAGE plpgsql
546
546
SET pg_pathman .enable_partitionfilter = off; /* ensures that PartitionFilter is OFF */
547
547
548
548
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
+
549
574
550
575
/*
551
576
* Create DDL trigger to call pathman_ddl_trigger_func().
Original file line number Diff line number Diff line change @@ -478,6 +478,8 @@ BEGIN
478
478
p_start_value,
479
479
p_end_value));
480
480
481
+ PERFORM @extschema@.copy_foreign_keys(parent_relid, v_child_relname::REGCLASS);
482
+
481
483
RETURN v_child_relname;
482
484
END
483
485
$$ LANGUAGE plpgsql
You can’t perform that action at this time.
0 commit comments