Skip to content

Commit

Permalink
Merge pull request #91478 from cockroachdb/blathers/backport-release-…
Browse files Browse the repository at this point in the history
…22.2-91307

Fixes #91301
  • Loading branch information
Marius Posta committed Nov 8, 2022
2 parents 7ac2f01 + 8e4167e commit b98e09f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/alter_primary_key
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ CREATE TABLE t (x INT PRIMARY KEY, y INT NOT NULL, z INT NOT NULL, w INT, INDEX
statement ok
INSERT INTO t VALUES (1, 2, 3, 4), (5, 6, 7, 8)

statement error pgcode 0A000 .* contains duplicate column \"y\"
ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (y, y)

statement ok
ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (y, z)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func checkForEarlyExit(b BuildCtx, tbl *scpb.Table, t alterPrimaryKeySpec) {
panic(err)
}

usedColumns := make(map[tree.Name]bool, len(t.Columns))
for _, col := range t.Columns {
if col.Column == "" && col.Expr != nil {
panic(errors.WithHint(
Expand All @@ -217,6 +218,11 @@ func checkForEarlyExit(b BuildCtx, tbl *scpb.Table, t alterPrimaryKeySpec) {
"use columns instead",
))
}
if usedColumns[col.Column] {
panic(pgerror.Newf(pgcode.FeatureNotSupported,
"new primary key contains duplicate column %q", col.Column))
}
usedColumns[col.Column] = true

colElems := b.ResolveColumn(tbl.TableID, col.Column, ResolveParams{
IsExistenceOptional: false,
Expand Down

0 comments on commit b98e09f

Please sign in to comment.