From 6ea563fe5bdf59d905fc7e302aca8e705bb8be46 Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Tue, 1 Aug 2017 20:00:36 +0800 Subject: [PATCH] Fix issue 3966, get_format(TIMESTAMP, 'USA') (#3976) --- expression/builtin_time.go | 9 +++++---- parser/parser.y | 6 +++++- parser/parser_test.go | 1 + 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/expression/builtin_time.go b/expression/builtin_time.go index b5cc6238ef..130c4fc5c5 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -34,9 +34,10 @@ import ( ) const ( // GET_FORMAT first argument. - dateFormat = "DATE" - datetimeFormat = "DATETIME" - timeFormat = "TIME" + dateFormat = "DATE" + datetimeFormat = "DATETIME" + timestampFormat = "TIMESTAMP" + timeFormat = "TIME" ) const ( // GET_FORMAT location. @@ -1129,7 +1130,7 @@ func (b *builtinGetFormatSig) eval(row []types.Datum) (d types.Datum, err error) case internalLocation: d.SetString("%Y%m%d") } - case datetimeFormat: + case datetimeFormat, timestampFormat: switch l { case usaLocation: d.SetString("%Y-%m-%d %H.%i.%s") diff --git a/parser/parser.y b/parser/parser.y index 3cff9dadce..f57da3bc91 100644 --- a/parser/parser.y +++ b/parser/parser.y @@ -862,7 +862,7 @@ import ( logAnd "logical and operator" logOr "logical or operator" FieldsOrColumns "Fields or columns" - GetFormatSelector "{DATE|DATETIME|TIME}" + GetFormatSelector "{DATE|DATETIME|TIME|TIMESTAMP}" %type Identifier "identifier or unreserved keyword" @@ -3826,6 +3826,10 @@ GetFormatSelector: { $$ = strings.ToUpper($1) } +| "TIMESTAMP" + { + $$ = strings.ToUpper($1) + } FunctionNameDateArith: diff --git a/parser/parser_test.go b/parser/parser_test.go index 14217515e9..991e3e1a5d 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -752,6 +752,7 @@ func (s *testParserSuite) TestBuiltin(c *C) { {"SELECT GET_FORMAT(DATE, 'USA');", true}, {"SELECT GET_FORMAT(DATETIME, 'USA');", true}, {"SELECT GET_FORMAT(TIME, 'USA');", true}, + {"SELECT GET_FORMAT(TIMESTAMP, 'USA');", true}, // for LOCALTIME, LOCALTIMESTAMP {"SELECT LOCALTIME(), LOCALTIME(1)", true},