diff --git a/types/convert_test.go b/types/convert_test.go index e8e4d69df945b..f6487f980bfe7 100644 --- a/types/convert_test.go +++ b/types/convert_test.go @@ -621,6 +621,9 @@ func (s *testTypeConvertSuite) TestConvert(c *C) { signedDeny(c, mysql.TypeYear, 123, "") signedDeny(c, mysql.TypeYear, 3000, "") signedAccept(c, mysql.TypeYear, "2000", "2000") + signedAccept(c, mysql.TypeYear, "abc", "0") + signedAccept(c, mysql.TypeYear, "00abc", "2000") + signedAccept(c, mysql.TypeYear, "0019", "2019") // time from string signedAccept(c, mysql.TypeDate, "2012-08-23", "2012-08-23") diff --git a/types/datum.go b/types/datum.go index 5c04ee1910939..06a7a8c9dc3bf 100644 --- a/types/datum.go +++ b/types/datum.go @@ -1186,7 +1186,9 @@ func (d *Datum) convertToMysqlYear(sc *stmtctx.StatementContext, target *FieldTy if err != nil { return ret, errors.Trace(err) } - adjust = len(s) < 4 + if len(s) != 4 && len(s) > 0 && s[0:1] == "0" { + adjust = true + } case KindMysqlTime: y = int64(d.GetMysqlTime().Time.Year()) case KindMysqlDuration: