From 0a9cff0ceb4f0e72c09551bcd2d40f31e245267c Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Thu, 29 Mar 2018 15:49:17 -0300 Subject: [PATCH v4 1/3] Refuse a FK pointing to a PK in a partitioned table --- src/backend/commands/tablecmds.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 83a881eff3..d0545495ae 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -7211,6 +7211,17 @@ ATAddForeignKeyConstraint(AlteredTableInfo *tab, Relation rel, pkrel = heap_openrv(fkconstraint->pktable, ShareRowExclusiveLock); /* + * Disallow a foreign key referencing a partitioned table; supporting this + * case requires more work. + */ + if (pkrel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("\"%s\" is a partitioned table", + RelationGetRelationName(pkrel)), + errdetail("Foreign keys cannot reference partitioned tables."))); + + /* * Validity checks (permission checks wait till we have the column * numbers) */ -- 2.11.0