forked from mirror/gorm
If size haven't been set, use `text` as string's default type for postgres, close #910
This commit is contained in:
parent
83002c4d5f
commit
55a8e63aad
|
@ -45,6 +45,10 @@ func (postgres) DataTypeOf(field *StructField) string {
|
||||||
case reflect.Float32, reflect.Float64:
|
case reflect.Float32, reflect.Float64:
|
||||||
sqlType = "numeric"
|
sqlType = "numeric"
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
|
if _, ok := field.TagSettings["SIZE"]; !ok {
|
||||||
|
size = 0 // if SIZE haven't been set, use `text` as the default type, as there are no performance different
|
||||||
|
}
|
||||||
|
|
||||||
if size > 0 && size < 65532 {
|
if size > 0 && size < 65532 {
|
||||||
sqlType = fmt.Sprintf("varchar(%d)", size)
|
sqlType = fmt.Sprintf("varchar(%d)", size)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue