Skip to content

Commit 58ec4b8

Browse files
author
James Cor
committed
tmp patch
1 parent 5c8664e commit 58ec4b8

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

sql/expression/convert.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ func convertValue(ctx *sql.Context, val interface{}, castTo string, originType s
366366
}
367367
return d, nil
368368
case ConvertToDouble, ConvertToReal:
369-
value, err := prepareForNumericContext(val, originType, false)
369+
//value, err := prepareForNumericContext(val, originType, false)
370+
value, err := types.ConvertOrTruncate(ctx, val, originType)
370371
if err != nil {
371372
return nil, err
372373
}

sql/types/conversion.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,13 @@ func TypeAwareConversion(ctx *sql.Context, val interface{}, originalType sql.Typ
766766
// ConvertOrTruncate converts the value |i| to type |t| and returns the converted value; if the value does not convert
767767
// cleanly and the type is automatically coerced (i.e. string and numeric types), then a warning is logged and the
768768
// value is truncated to the Zero value for type |t|. If the value does not convert and the type is not automatically
769-
// coerced, then an error is returned.
769+
// coerced, then return an error.
770770
func ConvertOrTruncate(ctx *sql.Context, i interface{}, t sql.Type) (interface{}, error) {
771+
// Do nothing if type is no provided.
772+
if t == nil {
773+
return i, nil
774+
}
775+
771776
converted, _, err := t.Convert(ctx, i)
772777
if err == nil {
773778
return converted, nil

sql/types/number.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,7 @@ func convertToFloat64(t NumberTypeImpl_, v interface{}) (float64, error) {
15371537
}
15381538
return float64(i), nil
15391539
case string:
1540+
// TODO: just trimStringToPrefix here
15401541
v = strings.Trim(v, NumericCutSet)
15411542
i, err := strconv.ParseFloat(v, 64)
15421543
if err != nil {

0 commit comments

Comments
 (0)