Skip to content

Commit

Permalink
parser: Add convert type function
Browse files Browse the repository at this point in the history
Support mysql builtin function CONVERT(expr,type)

See: https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_convert
  • Loading branch information
shenli committed Sep 6, 2015
1 parent a919e8c commit 05816bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,14 @@ Function:
Charset: $5.(string),
}
}
| "CONVERT" '(' Expression ',' CastType ')'
{
// See: https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_convert
$$ = &expressions.FunctionCast{
Expr: $3.(expression.Expression),
Tp: $5.(*types.FieldType),
}
}
| "SUBSTRING" '(' Expression ',' Expression ')'
{
$$ = &expressions.FunctionSubstring{
Expand Down
2 changes: 2 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ func (s *testParserSuite) TestParser0(c *C) {
{"SELECT SUBSTRING('Quadratically' FROM 5);", true},
{"SELECT SUBSTRING('Quadratically' FROM 5 FOR 3);", true},

{"SELECT CONVERT('111', SIGNED);", true},

// For delete statement
{"DELETE t1, t2 FROM t1 INNER JOIN t2 INNER JOIN t3 WHERE t1.id=t2.id AND t2.id=t3.id;", true},
{"DELETE FROM t1, t2 USING t1 INNER JOIN t2 INNER JOIN t3 WHERE t1.id=t2.id AND t2.id=t3.id;", true},
Expand Down

0 comments on commit 05816bd

Please sign in to comment.