mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
ATPrepAddPrimaryKey: ignore non-PK constraints
Because of lack of test coverage, this function added by b0e96f3119
wasn't ignoring constraint types other than primary keys, which it
should have. Add some lines to a test for it.
Reported-by: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/CAMbWs48bc-k_-1fh0dZpAhp_LiR5MfEX9haystmoBboR_4czCQ@mail.gmail.com
This commit is contained in:
@ -8907,7 +8907,14 @@ ATPrepAddPrimaryKey(List **wqueue, Relation rel, AlterTableCmd *cmd,
|
||||
List *children;
|
||||
List *newconstrs = NIL;
|
||||
ListCell *lc;
|
||||
IndexStmt *stmt;
|
||||
IndexStmt *indexstmt;
|
||||
|
||||
/* No work if not creating a primary key */
|
||||
if (!IsA(cmd->def, IndexStmt))
|
||||
return;
|
||||
indexstmt = castNode(IndexStmt, cmd->def);
|
||||
if (!indexstmt->primary)
|
||||
return;
|
||||
|
||||
/* No work if no legacy inheritance children are present */
|
||||
if (rel->rd_rel->relkind != RELKIND_RELATION ||
|
||||
@ -8916,8 +8923,7 @@ ATPrepAddPrimaryKey(List **wqueue, Relation rel, AlterTableCmd *cmd,
|
||||
|
||||
children = find_inheritance_children(RelationGetRelid(rel), lockmode);
|
||||
|
||||
stmt = castNode(IndexStmt, cmd->def);
|
||||
foreach(lc, stmt->indexParams)
|
||||
foreach(lc, indexstmt->indexParams)
|
||||
{
|
||||
IndexElem *elem = lfirst_node(IndexElem, lc);
|
||||
Constraint *nnconstr;
|
||||
|
Reference in New Issue
Block a user