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

ddl: use original column name in duplicate column error #9291

Merged
merged 4 commits into from Feb 14, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion ddl/column_test.go
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/table"
Expand Down Expand Up @@ -970,5 +971,6 @@ func (s *testColumnSuite) TestFieldCase(c *C) {
}
colObjects = append(colObjects, colDefs[i])
}
c.Assert(checkDuplicateColumn(colObjects), NotNil)
err := checkDuplicateColumn(colObjects)
c.Assert(err.Error(), Equals, infoschema.ErrColumnExists.GenWithStackByArgs("Field").Error())
}
14 changes: 7 additions & 7 deletions ddl/ddl_api.go
Expand Up @@ -629,20 +629,20 @@ func checkColumnValueConstraint(col *table.Column) error {

func checkDuplicateColumn(cols []interface{}) error {
colNames := set.StringSet{}
var nameLower string
colName := model.NewCIStr("")
for _, col := range cols {
switch x := col.(type) {
case *ast.ColumnDef:
nameLower = x.Name.Name.L
colName = x.Name.Name
case model.CIStr:
nameLower = x.L
colName = x
default:
nameLower = ""
colName.O, colName.L = "", ""
}
if colNames.Exist(nameLower) {
return infoschema.ErrColumnExists.GenWithStackByArgs(nameLower)
if colNames.Exist(colName.L) {
return infoschema.ErrColumnExists.GenWithStackByArgs(colName.O)
}
colNames.Insert(nameLower)
colNames.Insert(colName.L)
}
return nil
}
Expand Down