From d1b5f05a8837f0ef25e6268d2ce6f89626e31d1d Mon Sep 17 00:00:00 2001 From: Shen Li Date: Fri, 2 Dec 2016 14:21:48 +0800 Subject: [PATCH] plan: Fix date_format type infer (#2152) See: http://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_date-format --- plan/typeinferer.go | 2 +- plan/typeinferer_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/plan/typeinferer.go b/plan/typeinferer.go index 879adaea55c55..b6d50361f4705 100644 --- a/plan/typeinferer.go +++ b/plan/typeinferer.go @@ -309,7 +309,7 @@ func (v *typeInferrer) handleFuncCallExpr(x *ast.FuncCallExpr) { case "dayname", "version", "database", "user", "current_user", "concat", "concat_ws", "left", "lcase", "lower", "repeat", "replace", "ucase", "upper", "convert", "substring", - "substring_index", "trim", "ltrim", "rtrim", "reverse", "hex", "unhex": + "substring_index", "trim", "ltrim", "rtrim", "reverse", "hex", "unhex", "date_format": tp = types.NewFieldType(mysql.TypeVarString) chs = v.defaultCharset case "strcmp", "isnull": diff --git a/plan/typeinferer_test.go b/plan/typeinferer_test.go index 8c82b52960d2b..38e6cfb38b5b1 100644 --- a/plan/typeinferer_test.go +++ b/plan/typeinferer_test.go @@ -146,6 +146,7 @@ func (ts *testTypeInferrerSuite) TestInferType(c *C) { {"hex(12)", mysql.TypeVarString, "utf8"}, {"unhex('TiDB')", mysql.TypeVarString, "utf8"}, {"unhex(12)", mysql.TypeVarString, "utf8"}, + {"DATE_FORMAT('2009-10-04 22:23:00', '%W %M %Y')", mysql.TypeVarString, "utf8"}, } for _, ca := range cases { ctx := testKit.Se.(context.Context)