Fix issue 3966, get_format(TIMESTAMP, 'USA') (#3976)

This commit is contained in:
Jack Yu
2017-08-01 20:00:36 +08:00
committed by GitHub
parent d0dcb5b0a6
commit 6ea563fe5b
3 changed files with 11 additions and 5 deletions

View File

@ -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")

View File

@ -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 <ident>
Identifier "identifier or unreserved keyword"
@ -3826,6 +3826,10 @@ GetFormatSelector:
{
$$ = strings.ToUpper($1)
}
| "TIMESTAMP"
{
$$ = strings.ToUpper($1)
}
FunctionNameDateArith:

View File

@ -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},