Skip to content

Commit

Permalink
executor, expression: calculating the default value for datetime shou…
Browse files Browse the repository at this point in the history
…ld consider the time zone (#7655) (#7672)
  • Loading branch information
zz-jason authored and coocood committed Sep 20, 2018
1 parent fe3839a commit 2f1d8ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1628,3 +1628,16 @@ func (s *testSuite) TestUpdateDelete(c *C) {
tk.MustExec("admin check table ttt;")
tk.MustExec("drop table ttt")
}

func (s *testSuite) TestInsertDateTimeWithTimeZone(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec(`use test;`)
tk.MustExec(`set time_zone="+09:00";`)
tk.MustExec(`drop table if exists t;`)
tk.MustExec(`create table t (id int, c1 datetime not null default CURRENT_TIMESTAMP);`)
tk.MustExec(`set TIMESTAMP = 1234;`)
tk.MustExec(`insert t (id) values (1);`)
tk.MustQuery(`select * from t;`).Check(testkit.Rows(
`1 1970-01-01 09:20:34`,
))
}
2 changes: 1 addition & 1 deletion expression/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func GetTimeValue(ctx sessionctx.Context, v interface{}, tp byte, fsp int) (d ty
upperX := strings.ToUpper(x)
if upperX == strings.ToUpper(ast.CurrentTimestamp) {
value.Time = types.FromGoTime(defaultTime.Truncate(time.Duration(math.Pow10(9-fsp)) * time.Nanosecond))
if tp == mysql.TypeTimestamp {
if tp == mysql.TypeTimestamp || tp == mysql.TypeDatetime {
err = value.ConvertTimeZone(time.Local, ctx.GetSessionVars().GetTimeZone())
if err != nil {
return d, errors.Trace(err)
Expand Down

0 comments on commit 2f1d8ec

Please sign in to comment.