Skip to content

Commit de838d5

Browse files
committed
allow truncated strings when cast as date
1 parent 62efe69 commit de838d5

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

enginetest/queries/queries.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4285,6 +4285,12 @@ SELECT * FROM cte WHERE d = 2;`,
42854285
Query: "select cast('2020-01-01 12:34:56.123456' as datetime(6)) > cast('2020-01-01 12:34:56' as datetime)",
42864286
Expected: []sql.Row{{true}},
42874287
},
4288+
{
4289+
Query: "select cast('2020-01-01 a' as date)",
4290+
ExpectedWarning: 1292,
4291+
ExpectedWarningsCount: 1,
4292+
Expected: []sql.Row{{time.Date(2020, time.January, 1, 0, 0, 0, 0, time.UTC)}},
4293+
},
42884294
{
42894295
Query: `SELECT * FROM (SELECT * FROM (SELECT * FROM (SELECT * FROM othertable) othertable_one) othertable_two) othertable_three WHERE s2 = 'first'`,
42904296
Expected: []sql.Row{

sql/expression/convert.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,10 @@ func convertValue(ctx *sql.Context, val interface{}, castTo string, originType s
331331
}
332332
d, _, err := types.Date.Convert(ctx, val)
333333
if err != nil {
334-
return nil, err
334+
if !sql.ErrTruncatedIncorrect.Is(err) {
335+
return nil, err
336+
}
337+
ctx.Warn(mysql.ERTruncatedWrongValue, "%s", err.Error())
335338
}
336339
return d, nil
337340
case ConvertToDatetime:

0 commit comments

Comments
 (0)