From 41e45b96d244a77b7c42e9500fe56d2c6ccb5f51 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 15f9623547a3f..6e8cdfe21555a 100644 --- a/expression/builtin_other.go +++ b/expression/builtin_other.go @@ -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) diff --git a/expression/integration_test.go b/expression/integration_test.go index f4f3411b3bee2..8c7922ae36a38 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -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`)) +}