From 92062640524633e1821161ba78c93a0acc47195d Mon Sep 17 00:00:00 2001 From: Zhang Jian Date: Wed, 30 Jan 2019 12:13:00 +0800 Subject: [PATCH] expression: handle Float32 for builtin function Values() (#9215) --- expression/builtin_other.go | 3 +++ expression/integration_test.go | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/expression/builtin_other.go b/expression/builtin_other.go index 78f6bfdb2cc96..b820519a0e8ee 100644 --- a/expression/builtin_other.go +++ b/expression/builtin_other.go @@ -555,6 +555,9 @@ func (b *builtinValuesRealSig) evalReal(_ types.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) diff --git a/expression/integration_test.go b/expression/integration_test.go index 1739f95b63c63..e6805593f84d3 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -3512,3 +3512,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`)) +}