Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: modify the error message of insert time value (#20847) #20898

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions executor/insert_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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')")
Expand All @@ -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=''")
Expand Down