diff --git a/expression/builtin_time.go b/expression/builtin_time.go index da1601859ec56..44842541a41ff 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -4682,6 +4682,10 @@ func (b *builtinMakeTimeSig) evalDuration(row chunk.Row) (types.Duration, bool, var overflow bool // MySQL TIME datatype: https://dev.mysql.com/doc/refman/5.7/en/time.html // ranges from '-838:59:59.000000' to '838:59:59.000000' + if hour < 0 && mysql.HasUnsignedFlag(b.args[0].GetType().Flag) { + hour = 838 + overflow = true + } if hour < -838 { hour = -838 overflow = true diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index 72f1b3b16e5f8..dda5dbfc9d100 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -1939,6 +1939,23 @@ func (s *testEvaluatorSuite) TestMakeTime(c *C) { } } + // MAKETIME(CAST(-1 AS UNSIGNED),0,0); + tp1 := &types.FieldType{ + Tp: mysql.TypeLonglong, + Flag: mysql.UnsignedFlag, + Charset: charset.CharsetBin, + Collate: charset.CollationBin, + Flen: mysql.MaxIntWidth, + } + f := BuildCastFunction(s.ctx, &Constant{Value: types.NewDatum("-1"), RetType: types.NewFieldType(mysql.TypeString)}, tp1) + res, err := f.Eval(chunk.Row{}) + c.Assert(err, IsNil) + f1, err := maketime.getFunction(s.ctx, s.datumsToConstants([]types.Datum{res, makeDatums(0)[0], makeDatums(0)[0]})) + c.Assert(err, IsNil) + got, err := evalBuiltinFunc(f1, chunk.Row{}) + c.Assert(err, IsNil) + c.Assert(got.GetMysqlDuration().String(), Equals, "838:59:59") + tbl = []struct { Args []interface{} Want interface{}