@@ -337,7 +337,7 @@ func resolveAlterColumn(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.S
337
337
// We can't evaluate auto-increment until the end of the analysis, since we break adding a new auto-increment unique
338
338
// column into two steps: first add the column, then create the index. If there was no index created, that's an error.
339
339
if addedColumn {
340
- err = validateAutoIncrementAdd (sch , keyedColumns )
340
+ err = validateAutoIncrementModify (sch , keyedColumns )
341
341
if err != nil {
342
342
return nil , false , err
343
343
}
@@ -788,24 +788,12 @@ func removeInSchema(sch sql.Schema, colName, tableName string) sql.Schema {
788
788
return schCopy
789
789
}
790
790
791
- // validateAutoIncrementType returns true if the given type can be used with AUTO_INCREMENT
792
- func validateAutoIncrementType (t sql.Type ) bool {
793
- // Only integer types are allowed for auto_increment in MySQL 8.4+
794
- // All other types are not allowed: TEXT, VARCHAR, CHAR, BLOB, BINARY, VARBINARY,
795
- // FLOAT, DOUBLE, DATE, TIME, DATETIME, TIMESTAMP, YEAR, ENUM, SET, BIT, DECIMAL, JSON, GEOMETRY, etc.
796
- if types .IsInteger (t ) {
797
- return true
798
- }
799
-
800
- return false
801
- }
802
-
803
791
func validateAutoIncrementModify (schema sql.Schema , keyedColumns map [string ]bool ) error {
804
792
seen := false
805
793
for _ , col := range schema {
806
794
if col .AutoIncrement {
807
- // Check if column type is valid for auto_increment
808
- if ! validateAutoIncrementType (col .Type ) {
795
+ // Under MySQL 8.4+, AUTO_INCREMENT columns must be integer types.
796
+ if ! types . IsInteger (col .Type ) {
809
797
return sql .ErrInvalidColumnSpecifier .New (col .Name )
810
798
}
811
799
// keyedColumns == nil means they are trying to add auto_increment column
@@ -827,34 +815,6 @@ func validateAutoIncrementModify(schema sql.Schema, keyedColumns map[string]bool
827
815
return nil
828
816
}
829
817
830
- func validateAutoIncrementAdd (schema sql.Schema , keyColumns map [string ]bool ) error {
831
- seen := false
832
- for _ , col := range schema {
833
- if col .AutoIncrement {
834
- {
835
- // Check if column type is valid for auto_increment
836
- if ! validateAutoIncrementType (col .Type ) {
837
- return sql .ErrInvalidColumnSpecifier .New (col .Name )
838
- }
839
- if ! col .PrimaryKey && ! keyColumns [col .Name ] {
840
- // AUTO_INCREMENT col must be a key
841
- return sql .ErrInvalidAutoIncCols .New ()
842
- }
843
- if col .Default != nil {
844
- // AUTO_INCREMENT col cannot have default
845
- return sql .ErrInvalidAutoIncCols .New ()
846
- }
847
- if seen {
848
- // there can be at most one AUTO_INCREMENT col
849
- return sql .ErrInvalidAutoIncCols .New ()
850
- }
851
- seen = true
852
- }
853
- }
854
- }
855
- return nil
856
- }
857
-
858
818
func schToColMap (sch sql.Schema ) map [string ]* sql.Column {
859
819
colMap := make (map [string ]* sql.Column , len (sch ))
860
820
for _ , col := range sch {
0 commit comments