diff --git a/expression/builtin_time.go b/expression/builtin_time.go index b661f71818..d8fe5b3971 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -2757,11 +2757,9 @@ func (du *baseDateArithmitical) getDateFromDatetime(ctx sessionctx.Context, args return types.ZeroTime, true, err } - dateTp := mysql.TypeDate - if date.Type() == mysql.TypeDatetime || date.Type() == mysql.TypeTimestamp || types.IsClockUnit(unit) { - dateTp = mysql.TypeDatetime + if types.IsClockUnit(unit) { + date.SetType(mysql.TypeDatetime) } - date.SetType(dateTp) return date, false, nil } @@ -3030,11 +3028,9 @@ func (du *baseDateArithmitical) vecGetDateFromDatetime(b *baseBuiltinFunc, input continue } - dateTp := mysql.TypeDate - if dates[i].Type() == mysql.TypeDatetime || dates[i].Type() == mysql.TypeTimestamp || isClockUnit { - dateTp = mysql.TypeDatetime + if isClockUnit { + dates[i].SetType(mysql.TypeDatetime) } - dates[i].SetType(dateTp) } return nil } diff --git a/expression/integration_test.go b/expression/integration_test.go index 617aab9ff2..2a86d240b9 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -7722,6 +7722,15 @@ func (s *testIntegrationSerialSuite) TestClusteredIndexAndNewCollation(c *C) { tk.MustQuery("select * from t").Check(testkit.Rows("&")) } +func (s *testIntegrationSuite) TestIssue20860(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t;") + tk.MustExec("create table t(id int primary key, c int, d timestamp null default null)") + tk.MustExec("insert into t values(1, 2, '2038-01-18 20:20:30')") + c.Assert(tk.ExecToErr("update t set d = adddate(d, interval 1 day) where id < 10"), NotNil) +} + func (s *testIntegrationSerialSuite) TestIssue20608(c *C) { collate.SetNewCollationEnabledForTest(true) defer collate.SetNewCollationEnabledForTest(false)