expression: keep the original data type when doing date arithmetic operations (#20940)
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
Reference in New Issue
Block a user