mirror of https://github.com/citusdata/citus.git
Bugfix for creating foreign key
This commit fixes crash for adding foreign keys without specifying the referenced column crashes the backend.pull/1213/head
parent
e6e5f63d9d
commit
95f8382ca2
|
@ -1591,6 +1591,19 @@ ErrorIfUnsupportedAlterTableStmt(AlterTableStmt *alterTableStatement)
|
||||||
" on co-located tables.")));
|
" on co-located tables.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The following logic requires the referenced columns to exists in
|
||||||
|
* the statement. Otherwise, we cannot apply some of the checks.
|
||||||
|
*/
|
||||||
|
if (constraint->pk_attrs == NULL)
|
||||||
|
{
|
||||||
|
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
|
errmsg("cannot create foreign key constraint "
|
||||||
|
"because referenced column list is empty"),
|
||||||
|
errhint("Add column names to \"REFERENCES\" part of "
|
||||||
|
"the statement.")));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Referencing column's list length should be equal to referenced columns
|
* Referencing column's list length should be equal to referenced columns
|
||||||
* list length.
|
* list length.
|
||||||
|
|
|
@ -462,6 +462,10 @@ SELECT create_distributed_table('referencing_table', 'ref_id', 'hash');
|
||||||
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
-- columns for the referenced table is empty
|
||||||
|
ALTER TABLE referencing_table ADD CONSTRAINT test_constraint FOREIGN KEY(ref_id) REFERENCES referenced_table ON DELETE CASCADE;
|
||||||
|
ERROR: cannot create foreign key constraint because referenced column list is empty
|
||||||
|
HINT: Add column names to "REFERENCES" part of the statement.
|
||||||
-- test foreign constraint creation on non-partition columns
|
-- test foreign constraint creation on non-partition columns
|
||||||
ALTER TABLE referencing_table ADD CONSTRAINT test_constraint FOREIGN KEY(id) REFERENCES referenced_table(id);
|
ALTER TABLE referencing_table ADD CONSTRAINT test_constraint FOREIGN KEY(id) REFERENCES referenced_table(id);
|
||||||
ERROR: cannot create foreign key constraint
|
ERROR: cannot create foreign key constraint
|
||||||
|
|
|
@ -254,6 +254,9 @@ CREATE TABLE referencing_table(id int, ref_id int);
|
||||||
SELECT create_distributed_table('referenced_table', 'id', 'hash');
|
SELECT create_distributed_table('referenced_table', 'id', 'hash');
|
||||||
SELECT create_distributed_table('referencing_table', 'ref_id', 'hash');
|
SELECT create_distributed_table('referencing_table', 'ref_id', 'hash');
|
||||||
|
|
||||||
|
-- columns for the referenced table is empty
|
||||||
|
ALTER TABLE referencing_table ADD CONSTRAINT test_constraint FOREIGN KEY(ref_id) REFERENCES referenced_table ON DELETE CASCADE;
|
||||||
|
|
||||||
-- test foreign constraint creation on non-partition columns
|
-- test foreign constraint creation on non-partition columns
|
||||||
ALTER TABLE referencing_table ADD CONSTRAINT test_constraint FOREIGN KEY(id) REFERENCES referenced_table(id);
|
ALTER TABLE referencing_table ADD CONSTRAINT test_constraint FOREIGN KEY(id) REFERENCES referenced_table(id);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue