diff --git a/executor/insert_common.go b/executor/insert_common.go index 3e2a592e2e8dc..ec9a437a77144 100644 --- a/executor/insert_common.go +++ b/executor/insert_common.go @@ -37,9 +37,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/execdetails" - "github.com/pingcap/tidb/util/logutil" "github.com/pingcap/tidb/util/memory" - "go.uber.org/zap" ) // InsertValues is the data to insert. @@ -293,10 +291,18 @@ func (e *InsertValues) handleErr(col *table.Column, val *types.Datum, rowIdx int err = types.ErrWarnDataOutOfRange.GenWithStackByArgs(colName, rowIdx+1) } else if types.ErrTruncated.Equal(err) { err = types.ErrTruncated.GenWithStackByArgs(colName, rowIdx+1) + } else if types.ErrTruncatedWrongVal.Equal(err) && (colTp == mysql.TypeDuration || colTp == mysql.TypeDatetime || colTp == mysql.TypeDate || colTp == mysql.TypeTimestamp) { + valStr, err1 := val.ToString() + if err1 != nil { + // do nothing + } + err = types.ErrTruncatedWrongVal.GenWithStack( + fmt.Sprintf("Incorrect %-.32s value: '%-.128s' for column '%.192s' at row %d", types.TypeStr(colTp), valStr, colName, rowIdx+1), + ) } else if types.ErrTruncatedWrongVal.Equal(err) || types.ErrWrongValue.Equal(err) { valStr, err1 := val.ToString() if err1 != nil { - logutil.BgLogger().Warn("truncate value failed", zap.Error(err1)) + // do nothing } err = table.ErrTruncatedWrongValueForField.GenWithStackByArgs(types.TypeStr(colTp), valStr, colName, rowIdx+1) } diff --git a/executor/write_test.go b/executor/write_test.go index 1e9c95c3f336f..c3f2f1cf62569 100644 --- a/executor/write_test.go +++ b/executor/write_test.go @@ -262,7 +262,7 @@ func (s *testSuite) TestInsert(c *C) { r.Check(testkit.Rows("0", "0", "18446744073709551615", "0", "0")) tk.MustExec("set @@sql_mode = @orig_sql_mode;") - // issue 6424 + // issue 6424 & issue 20207 tk.MustExec("drop table if exists t") tk.MustExec("create table t(a time(6))") tk.MustExec("insert into t value('20070219173709.055870'), ('20070219173709.055'), ('20070219173709.055870123')") @@ -271,7 +271,7 @@ func (s *testSuite) TestInsert(c *C) { tk.MustExec("insert into t value(20070219173709.055870), (20070219173709.055), (20070219173709.055870123)") tk.MustQuery("select * from t").Check(testkit.Rows("17:37:09.055870", "17:37:09.055000", "17:37:09.055870")) _, err = tk.Exec("insert into t value(-20070219173709.055870)") - c.Assert(err.Error(), Equals, "[table:1366]Incorrect time value: '-20070219173709.055870' for column 'a' at row 1") + c.Assert(err.Error(), Equals, "[types:1292]Incorrect time value: '-20070219173709.055870' for column 'a' at row 1") tk.MustExec("drop table if exists t") tk.MustExec("set @@sql_mode=''")