Skip to content

Commit 2f1d8ec

Browse files
zz-jasoncoocood
authored andcommitted
executor, expression: calculating the default value for datetime should consider the time zone (#7655) (#7672)
1 parent fe3839a commit 2f1d8ec

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

executor/write_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,3 +1628,16 @@ func (s *testSuite) TestUpdateDelete(c *C) {
16281628
tk.MustExec("admin check table ttt;")
16291629
tk.MustExec("drop table ttt")
16301630
}
1631+
1632+
func (s *testSuite) TestInsertDateTimeWithTimeZone(c *C) {
1633+
tk := testkit.NewTestKit(c, s.store)
1634+
tk.MustExec(`use test;`)
1635+
tk.MustExec(`set time_zone="+09:00";`)
1636+
tk.MustExec(`drop table if exists t;`)
1637+
tk.MustExec(`create table t (id int, c1 datetime not null default CURRENT_TIMESTAMP);`)
1638+
tk.MustExec(`set TIMESTAMP = 1234;`)
1639+
tk.MustExec(`insert t (id) values (1);`)
1640+
tk.MustQuery(`select * from t;`).Check(testkit.Rows(
1641+
`1 1970-01-01 09:20:34`,
1642+
))
1643+
}

expression/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func GetTimeValue(ctx sessionctx.Context, v interface{}, tp byte, fsp int) (d ty
5959
upperX := strings.ToUpper(x)
6060
if upperX == strings.ToUpper(ast.CurrentTimestamp) {
6161
value.Time = types.FromGoTime(defaultTime.Truncate(time.Duration(math.Pow10(9-fsp)) * time.Nanosecond))
62-
if tp == mysql.TypeTimestamp {
62+
if tp == mysql.TypeTimestamp || tp == mysql.TypeDatetime {
6363
err = value.ConvertTimeZone(time.Local, ctx.GetSessionVars().GetTimeZone())
6464
if err != nil {
6565
return d, errors.Trace(err)

0 commit comments

Comments
 (0)