From a5a7869a4a5cb946994b489f074411937f5d6b2e Mon Sep 17 00:00:00 2001 From: b41sh Date: Sat, 13 Jul 2019 18:12:16 +0800 Subject: [PATCH] fix NAME_CONST --- expression/integration_test.go | 4 ++++ planner/core/preprocess.go | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index ff0ccb762251a..6b26fc23054da 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -4077,6 +4077,10 @@ func (s *testIntegrationSuite) TestFuncNameConst(c *C) { r.Check(testkit.Rows("2")) r = tk.MustQuery("SELECT concat('hello', name_const('test_string', 'world')) FROM t;") r.Check(testkit.Rows("helloworld")) + r = tk.MustQuery("SELECT NAME_CONST('come', -1);") + r.Check(testkit.Rows("-1")) + r = tk.MustQuery("SELECT NAME_CONST('come', -1.0);") + r.Check(testkit.Rows("-1.0")) err := tk.ExecToErr(`select name_const(a,b) from t;`) c.Assert(err.Error(), Equals, "[planner:1210]Incorrect arguments to NAME_CONST") err = tk.ExecToErr(`select name_const(a,"hello") from t;`) diff --git a/planner/core/preprocess.go b/planner/core/preprocess.go index 26d93eabaf9ab..770ba6f683e5a 100644 --- a/planner/core/preprocess.go +++ b/planner/core/preprocess.go @@ -178,7 +178,12 @@ func (p *preprocessor) Leave(in ast.Node) (out ast.Node, ok bool) { p.err = expression.ErrIncorrectParameterCount.GenWithStackByArgs(x.FnName.L) } else { _, isValueExpr1 := x.Args[0].(*driver.ValueExpr) - _, isValueExpr2 := x.Args[1].(*driver.ValueExpr) + isValueExpr2 := false + switch x.Args[1].(type) { + case *driver.ValueExpr, *ast.UnaryOperationExpr: + isValueExpr2 = true + } + if !isValueExpr1 || !isValueExpr2 { p.err = ErrWrongArguments.GenWithStackByArgs("NAME_CONST") }