Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor, expression: calculating the default value for datetime should consider the time zone #7655

Merged
merged 3 commits into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions executor/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,18 @@ func (s *testSuite) TestInsertWrongValueForField(c *C) {
_, err := tk.Exec(`insert into t1 values("asfasdfsajhlkhlksdaf");`)
c.Assert(terror.ErrorEqual(err, table.ErrTruncatedWrongValueForField), IsTrue)
}

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().Location())
if err != nil {
return d, errors.Trace(err)
Expand Down