Skip to content

Commit 97b350e

Browse files
authored
Merge pull request #2825 from dolthub/zachmu/validate-defaults-bug
Bug fixes for serializing certain types in column default expressions
2 parents f5a5bce + 88dcda4 commit 97b350e

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

sql/analyzer/resolve_column_defaults.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,27 @@ func normalizeDefault(ctx *sql.Context, colDefault *sql.ColumnDefaultValue) (sql
438438
return colDefault, transform.SameTree, nil
439439
}
440440
typ := colDefault.Type()
441-
if types.IsTime(typ) || types.IsTimespan(typ) || types.IsEnum(typ) || types.IsSet(typ) || types.IsJSON(typ) {
441+
if skipDefaultNormalizationForType(typ) {
442442
return colDefault, transform.SameTree, nil
443443
}
444444
val, err := colDefault.Eval(ctx, nil)
445445
if err != nil {
446446
return colDefault, transform.SameTree, nil
447447
}
448-
colDefault.Expr = expression.NewLiteral(val, typ)
449-
return colDefault, transform.NewTree, nil
448+
449+
newDefault, err := colDefault.WithChildren(expression.NewLiteral(val, typ))
450+
if err != nil {
451+
return nil, transform.SameTree, err
452+
}
453+
return newDefault, transform.NewTree, nil
454+
}
455+
456+
// skipDefaultNormalizationForType returns true if the default value for the given type should not be normalized for
457+
// serialization before being passed to the integrator for table creation
458+
func skipDefaultNormalizationForType(typ sql.Type) bool {
459+
// Extended types handle their own serialization concerns
460+
if _, ok := typ.(types.ExtendedType); ok {
461+
return true
462+
}
463+
return types.IsTime(typ) || types.IsTimespan(typ) || types.IsEnum(typ) || types.IsSet(typ) || types.IsJSON(typ)
450464
}

0 commit comments

Comments
 (0)