diff --git a/executor/insert_test.go b/executor/insert_test.go index 6f0c1b0e01dbe..24d8a12184c3f 100644 --- a/executor/insert_test.go +++ b/executor/insert_test.go @@ -271,6 +271,11 @@ func (s *testSuite3) TestInsertWrongValueForField(c *C) { tk.MustExec(`create table t1(a bigint);`) _, err := tk.Exec(`insert into t1 values("asfasdfsajhlkhlksdaf");`) c.Assert(terror.ErrorEqual(err, table.ErrTruncatedWrongValueForField), IsTrue) + + tk.MustExec(`drop table if exists t;`) + tk.MustExec(`create table t (a year);`) + _, err = tk.Exec(`insert into t values(2156);`) + c.Assert(err.Error(), Equals, `[types:1264]Out of range value for column 'a' at row 1`) } func (s *testSuite3) TestInsertDateTimeWithTimeZone(c *C) { diff --git a/executor/write_test.go b/executor/write_test.go index d024abbc2ba1b..e00b5543bb1b5 100644 --- a/executor/write_test.go +++ b/executor/write_test.go @@ -1469,7 +1469,7 @@ func (s *testSuite8) TestUpdate(c *C) { tk.MustExec("drop table t") tk.MustExec("CREATE TABLE `t` ( `c1` year DEFAULT NULL, `c2` year DEFAULT NULL, `c3` date DEFAULT NULL, `c4` datetime DEFAULT NULL, KEY `idx` (`c1`,`c2`))") _, err = tk.Exec("UPDATE t SET c2=16777215 WHERE c1>= -8388608 AND c1 < -9 ORDER BY c1 LIMIT 2") - c.Assert(err.Error(), Equals, "cannot convert datum from bigint to type year.") + c.Assert(err.Error(), Equals, "[types:1690]DECIMAL value is out of range in '(4, 0)'") tk.MustExec("update (select * from t) t set c1 = 1111111") diff --git a/types/datum.go b/types/datum.go index c0c747969ed78..e9a14008d7fd9 100644 --- a/types/datum.go +++ b/types/datum.go @@ -1356,7 +1356,7 @@ func (d *Datum) convertToMysqlYear(sc *stmtctx.StatementContext, target *FieldTy } y, err = AdjustYear(y, adjust) if err != nil { - _, err = invalidConv(d, target.Tp) + err = ErrOverflow.GenWithStackByArgs("DECIMAL", fmt.Sprintf("(%d, %d)", target.Flen, target.Decimal)) } ret.SetInt64(y) return ret, err