If size haven't been set, use `text` as string's default type for postgres, close #910

This commit is contained in:
Jinzhu 2016-03-16 23:06:15 +08:00
parent 83002c4d5f
commit 55a8e63aad
1 changed files with 4 additions and 0 deletions

View File

@ -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 {