Skip to content

Commit 247f89a

Browse files
elianddbclaude
andcommitted
Fix enum columns cannot have auto_increment
Added validation to prevent enum columns from being used with auto_increment. This matches MySQL behavior where auto_increment can only be used with numeric types. Changes: - Added ErrInvalidColumnSpecifier error message - Added enum type validation in validateAutoIncrementModify and validateAutoIncrementAdd - Enabled previously skipped test case for enum auto_increment validation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 1af0f6e commit 247f89a

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

enginetest/queries/script_queries.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9000,7 +9000,7 @@ where
90009000
},
90019001
},
90029002
{
9003-
Skip: true,
9003+
Skip: false,
90049004
Name: "enums with auto increment",
90059005
Dialect: "mysql",
90069006
SetUpScript: []string{},

sql/analyzer/validate_create_table.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,10 @@ func validateAutoIncrementModify(schema sql.Schema, keyedColumns map[string]bool
791791
seen := false
792792
for _, col := range schema {
793793
if col.AutoIncrement {
794+
// Check if column type is valid for auto_increment
795+
if types.IsEnum(col.Type) {
796+
return sql.ErrInvalidColumnSpecifier.New(col.Name)
797+
}
794798
// keyedColumns == nil means they are trying to add auto_increment column
795799
if !col.PrimaryKey && !keyedColumns[col.Name] {
796800
// AUTO_INCREMENT col must be a key
@@ -815,6 +819,10 @@ func validateAutoIncrementAdd(schema sql.Schema, keyColumns map[string]bool) err
815819
for _, col := range schema {
816820
if col.AutoIncrement {
817821
{
822+
// Check if column type is valid for auto_increment
823+
if types.IsEnum(col.Type) {
824+
return sql.ErrInvalidColumnSpecifier.New(col.Name)
825+
}
818826
if !col.PrimaryKey && !keyColumns[col.Name] {
819827
// AUTO_INCREMENT col must be a key
820828
return sql.ErrInvalidAutoIncCols.New()

sql/errors.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,9 @@ var (
669669
// ErrInvalidAutoIncCols is returned when an auto_increment column cannot be applied
670670
ErrInvalidAutoIncCols = errors.NewKind("there can be only one auto_increment column and it must be defined as a key")
671671

672+
// ErrInvalidColumnSpecifier is returned when an invalid column specifier is used
673+
ErrInvalidColumnSpecifier = errors.NewKind("Incorrect column specifier for column '%s'")
674+
672675
// ErrUnknownConstraintDefinition is returned when an unknown constraint type is used
673676
ErrUnknownConstraintDefinition = errors.NewKind("unknown constraint definition: %s, %T")
674677

0 commit comments

Comments
 (0)