[parser] parser: support cast as double (#399)

This commit is contained in:
wshwsh12
2019-07-26 12:59:44 +08:00
committed by Ti Chi Robot
parent 5924cf2f8c
commit f100bfdd65
5 changed files with 2874 additions and 2848 deletions

View File

@ -79,6 +79,7 @@ var defaultLengthAndDecimalForCast = map[byte]lengthAndDecimal{
TypeNewDecimal: {11, 0},
TypeDuration: {10, 0},
TypeLonglong: {22, 0},
TypeDouble: {22, -1},
TypeJSON: {4194304, 0}, // Flen differs.
}

File diff suppressed because it is too large Load Diff

View File

@ -5071,6 +5071,15 @@ CastType:
x.Collate = mysql.DefaultCollationName
$$ = x
}
| "DOUBLE"
{
x := types.NewFieldType(mysql.TypeDouble)
x.Flen, x.Decimal = mysql.GetDefaultFieldLengthAndDecimalForCast(mysql.TypeDouble)
x.Flag |= mysql.BinaryFlag
x.Charset = charset.CharsetBin
x.Collate = charset.CollationBin
$$ = x
}
PriorityOpt:
{

View File

@ -1105,6 +1105,9 @@ func (s *testParserSuite) TestBuiltin(c *C) {
// for cast as signed int, fix issue #3691.
{"select cast(1 as signed int);", true, "SELECT CAST(1 AS SIGNED)"},
// for cast as double
{"select cast(1 as double);", true, "SELECT CAST(1 AS DOUBLE)"},
// for last_insert_id
{"SELECT last_insert_id();", true, "SELECT LAST_INSERT_ID()"},
{"SELECT last_insert_id(1);", true, "SELECT LAST_INSERT_ID(1)"},

View File

@ -299,6 +299,8 @@ func (ft *FieldType) RestoreAsCastType(ctx *format.RestoreCtx) {
}
case mysql.TypeJSON:
ctx.WriteKeyWord("JSON")
case mysql.TypeDouble:
ctx.WriteKeyWord("DOUBLE")
}
}