Skip to content

uint8 in Golang should correspond to tinyint in SQL Server #128

Open
@iTanken

Description

@iTanken

sqlserver/sqlserver.go

Lines 188 to 202 in ef8f762

case schema.Int, schema.Uint:
var sqlType string
switch {
case field.Size < 16:
sqlType = "smallint"
case field.Size < 31:
sqlType = "int"
default:
sqlType = "bigint"
}
if field.AutoIncrement {
return sqlType + " IDENTITY(1,1)"
}
return sqlType

Because in SQL Server, the range of values for the tinyint type is from 0 to 255, which exactly matches the range of uint8, so when field.Size < 16 and field.DataType == schema.Uint, should sqlType be tinyint? Like this:

 case schema.Int, schema.Uint:
 	var sqlType string
 	switch {
 	case field.Size < 16:
		if field.DataType == schema.Uint {
			sqlType = "tinyint"
		} else {
			sqlType = "smallint"
		}
 	case field.Size < 31:
 		sqlType = "int"
 	default:
 		sqlType = "bigint"
 	}
  
 	if field.AutoIncrement {
 		return sqlType + " IDENTITY(1,1)"
 	}
 	return sqlType

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions