Skip to content

Commit

Permalink
expression: handle Float32 for builtin function Values() (#9215) (#9223)
Browse files Browse the repository at this point in the history
  • Loading branch information
zz-jason authored Jan 30, 2019
1 parent 0280bcd commit 82f8d55
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions expression/builtin_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,9 @@ func (b *builtinValuesRealSig) evalReal(_ chunk.Row) (float64, bool, error) {
if row.IsNull(b.offset) {
return 0, true, nil
}
if b.getRetTp().Tp == mysql.TypeFloat {
return float64(row.GetFloat32(b.offset)), false, nil
}
return row.GetFloat64(b.offset), false, nil
}
return 0, true, errors.Errorf("Session current insert values len %d and column's offset %v don't match", row.Len(), b.offset)
Expand Down
11 changes: 11 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3785,3 +3785,14 @@ func (s *testIntegrationSuite) TestCastAsTime(c *C) {
c.Assert(err.Error(), Equals, "[expression:1426]Too big precision 31 specified for column 'CAST'. Maximum is 6.")
c.Assert(rs, IsNil)
}

func (s *testIntegrationSuite) TestValuesFloat32(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec(`drop table if exists t;`)
tk.MustExec(`create table t (i int key, j float);`)
tk.MustExec(`insert into t values (1, 0.01);`)
tk.MustQuery(`select * from t;`).Check(testkit.Rows(`1 0.01`))
tk.MustExec(`insert into t values (1, 0.02) on duplicate key update j = values (j);`)
tk.MustQuery(`select * from t;`).Check(testkit.Rows(`1 0.02`))
}

0 comments on commit 82f8d55

Please sign in to comment.