diff --git a/expression/integration_test.go b/expression/integration_test.go index ac1c88d37e389..86962d6de8b0f 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -2029,6 +2029,17 @@ func (s *testIntegrationSuite) TestTimeBuiltin(c *C) { result.Check(testkit.Rows("")) result = tk.MustQuery(`select tidb_parse_tso(-1)`) result.Check(testkit.Rows("")) + + // fix issue 10308 + result = tk.MustQuery("select time(\"- -\");") + result.Check(testkit.Rows("00:00:00")) + tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect time value: '- -'")) + result = tk.MustQuery("select time(\"---1\");") + result.Check(testkit.Rows("00:00:00")) + tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect time value: '---1'")) + result = tk.MustQuery("select time(\"-- --1\");") + result.Check(testkit.Rows("00:00:00")) + tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect time value: '-- --1'")) } func (s *testIntegrationSuite) TestOpBuiltin(c *C) { diff --git a/types/time.go b/types/time.go index 941951f2cb887..253fc537688f3 100644 --- a/types/time.go +++ b/types/time.go @@ -17,6 +17,7 @@ import ( "bytes" "context" "fmt" + "io" "math" "regexp" "strconv" @@ -1169,6 +1170,9 @@ func ParseDuration(sc *stmtctx.StatementContext, str string, fsp int) (Duration, return ZeroDuration, ErrTruncatedWrongVal.GenWithStackByArgs("time", origStr) } + if terror.ErrorEqual(err, io.EOF) { + err = ErrTruncatedWrongVal.GenWithStackByArgs("time", origStr) + } if err != nil { return ZeroDuration, errors.Trace(err) }