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

integer data type selection by sizing should be fixed #52

Closed
rafiulgits opened this issue Feb 19, 2022 · 1 comment
Closed

integer data type selection by sizing should be fixed #52

rafiulgits opened this issue Feb 19, 2022 · 1 comment

Comments

@rafiulgits
Copy link
Contributor

switch {

SQL Server datatype selection based on int value data size is not appropriate. Here is the condition

switch {
case field.Size < 16:
	sqlType = "smallint"
case field.Size < 31:
	sqlType = "int"
default:
	sqlType = "bigint"
}

Golang integers

  • int8 : 1 byte or 8 bits
  • int16: 2 bytes or 16 bits
  • int32: 3 bytes or 32 bits
  • int64 4 bytes or 64 bits`

SQL Server integers equivalent

  • tinyint : int8
  • smallint : int16
  • int : int32
  • biging : int64

The condition should be

switch {
case field.Size < 16:
	sqlType = "tinyint"
case field.Size < 31:
	sqlType = "smallint"
case field.Size < 64:
	sqlType = "int"
default:
	sqlType = "bigint"
}
@rafiulgits
Copy link
Contributor Author

I have created a pull request #53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant