fix postgres default

This commit is contained in:
Lunny Xiao 2019-09-27 22:00:04 +08:00
parent 725e720559
commit 7ebd9c4fe2
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
1 changed files with 13 additions and 13 deletions

View File

@ -1005,16 +1005,18 @@ WHERE c.relkind = 'r'::char AND c.relname = $1%s AND f.attnum > 0 ORDER BY f.att
col.Name = strings.Trim(colName, `" `)
if colDefault != nil || isPK {
if isPK {
col.IsPrimaryKey = true
} else {
if colDefault != nil {
col.Default = *colDefault
col.DefaultIsEmpty = false
if strings.HasPrefix(col.Default, "nextval(") {
col.IsAutoIncrement = true
}
} else {
col.DefaultIsEmpty = true
}
if colDefault != nil && strings.HasPrefix(*colDefault, "nextval(") {
col.IsAutoIncrement = true
if isPK {
col.IsPrimaryKey = true
}
col.Nullable = (isNullable == "YES")
@ -1043,13 +1045,11 @@ WHERE c.relkind = 'r'::char AND c.relname = $1%s AND f.attnum > 0 ORDER BY f.att
col.Length = maxLen
if col.SQLType.IsText() || col.SQLType.IsTime() {
if col.Default != "" {
col.Default = "'" + col.Default + "'"
} else {
if col.DefaultIsEmpty {
if !col.DefaultIsEmpty && (col.SQLType.IsText() || col.SQLType.IsTime()) {
if col.Default == "''::character varying" {
col.Default = "''"
}
} else if !strings.HasPrefix(col.Default, "'") {
col.Default = "'" + col.Default + "'"
}
}
cols[col.Name] = col