Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit562cab6

Browse files
committed
introduce function copy_foreign_keys(), generate fkeys on children
1 parent1bcb666 commit562cab6

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

‎hash.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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*/

‎init.sql

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,31 @@ $$ LANGUAGE plpgsql
546546
SETpg_pathman.enable_partitionfilter= off;/* ensures that PartitionFilter is OFF*/
547547

548548

549+
/*
550+
* Copy all of parent's foreign keys.
551+
*/
552+
CREATEOR REPLACE FUNCTION @extschema@.copy_foreign_keys(
553+
parent_relidREGCLASS,
554+
partitionREGCLASS)
555+
RETURNS VOIDAS
556+
$$
557+
DECLARE
558+
recRECORD;
559+
560+
BEGIN
561+
PERFORM @extschema@.validate_relname(parent_relid);
562+
PERFORM @extschema@.validate_relname(partition);
563+
564+
FOR recIN (SELECToidas conidFROMpg_catalog.pg_constraint
565+
WHERE conrelid= parent_relidAND 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().

‎range.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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;
482484
END
483485
$$ LANGUAGE plpgsql

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp