Skip to content

Commit

Permalink
fix(mysql): transpile MONTHNAME (#2222)
Browse files Browse the repository at this point in the history
  • Loading branch information
barakalon authored Sep 14, 2023
1 parent 6bc8e13 commit 2fa4043
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sqlglot/dialects/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,13 @@ class Parser(parser.Parser):
"DATE_FORMAT": format_time_lambda(exp.TimeToStr, "mysql"),
"DATE_SUB": parse_date_delta_with_interval(exp.DateSub),
"INSTR": lambda args: exp.StrPosition(substr=seq_get(args, 1), this=seq_get(args, 0)),
"ISNULL": isnull_to_is_null,
"LOCATE": locate_to_strposition,
"MONTHNAME": lambda args: exp.TimeToStr(
this=seq_get(args, 0),
format=exp.Literal.string("%B"),
),
"STR_TO_DATE": _str_to_date,
"ISNULL": isnull_to_is_null,
}

FUNCTION_PARSERS = {
Expand Down
9 changes: 9 additions & 0 deletions tests/dialects/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,3 +876,12 @@ def test_is_null(self):
self.validate_all(
"SELECT ISNULL(x)", write={"": "SELECT (x IS NULL)", "mysql": "SELECT (x IS NULL)"}
)

def test_monthname(self):
self.validate_all(
"MONTHNAME(x)",
write={
"": "TIME_TO_STR(x, '%B')",
"mysql": "DATE_FORMAT(x, '%M')",
},
)

0 comments on commit 2fa4043

Please sign in to comment.