aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/tablecmds.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2023-09-01 14:21:27 +0200
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2023-09-01 14:21:27 +0200
commite09d763e25dccc40695bc824ddda9abea791d66f (patch)
tree479cecdc55e0e94c3f9430f779285086fc324925 /src/backend/commands/tablecmds.c
parente8d74ad625f7344f6b715254d3869663c1569a51 (diff)
downloadpostgresql-e09d763e25dccc40695bc824ddda9abea791d66f.tar.gz
postgresql-e09d763e25dccc40695bc824ddda9abea791d66f.zip
ATPrepAddPrimaryKey: ignore non-PK constraints
Because of lack of test coverage, this function added by b0e96f311985 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
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r--src/backend/commands/tablecmds.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index d097da3c78e..03397746724 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -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;