Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-22.2: scbuild: error on duplicate columns in ALTER PRIMARY KEY #91478

Merged
merged 1 commit into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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