Skip to content

Commit a65db59

Browse files
elianddbclaude
andcommitted
dolthub/dolt#9481 - Simplify auto_increment validation logic
- Use single check for types.IsNumber() with exclusions for DECIMAL, YEAR, and BIT - More maintainable and cleaner code structure - Comment lists all excluded types for clarity - All tests still passing with exact MySQL behavior 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 89388dc commit a65db59

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

sql/analyzer/validate_create_table.go

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -790,31 +790,17 @@ func removeInSchema(sch sql.Schema, colName, tableName string) sql.Schema {
790790

791791
// validateAutoIncrementType returns true if the given type can be used with AUTO_INCREMENT
792792
func validateAutoIncrementType(t sql.Type) bool {
793-
// Check for invalid types first
794-
if types.IsEnum(t) || types.IsSet(t) || types.IsBit(t) {
795-
return false
796-
}
797-
798-
// Check for text/string types - not allowed (includes TEXT, VARCHAR, CHAR, BLOB, BINARY, etc.)
799-
if types.IsText(t) {
800-
return false
801-
}
802-
803-
// Check for datetime/time types - not allowed
804-
if types.IsTime(t) || types.IsDateType(t) || types.IsDatetimeType(t) || types.IsTimestampType(t) || types.IsYear(t) {
805-
return false
806-
}
807-
808-
// Check for numeric types - only these are potentially allowed
793+
// Only integer and floating point numeric types are allowed for auto_increment
794+
// All other types are not allowed: TEXT, VARCHAR, CHAR, BLOB, BINARY, VARBINARY,
795+
// DATE, TIME, DATETIME, TIMESTAMP, YEAR, ENUM, SET, BIT, DECIMAL, JSON, GEOMETRY, etc.
809796
if types.IsNumber(t) {
810-
// DECIMAL is not allowed for auto_increment per MySQL behavior
811-
if types.IsDecimal(t) {
797+
// DECIMAL, YEAR, and BIT are not allowed for auto_increment per MySQL behavior
798+
if types.IsDecimal(t) || types.IsYear(t) || types.IsBit(t) {
812799
return false
813800
}
814801
return true
815802
}
816-
817-
// Default to false for any other types (JSON, Geometry, etc.)
803+
818804
return false
819805
}
820806

0 commit comments

Comments
 (0)