Skip to content

Commit

Permalink
Fix(mysql): generate TimeStrToTime as a cast to TIMESTAMP (#1968)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesittas authored Jul 27, 2023
1 parent d2685dd commit 1ebe49f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sqlglot/dialects/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
parse_date_delta_with_interval,
rename_func,
strposition_to_locate_sql,
timestrtotime_sql,
)
from sqlglot.helper import seq_get
from sqlglot.tokens import TokenType
Expand Down Expand Up @@ -521,6 +522,7 @@ class Generator(generator.Generator):
exp.StrToTime: _str_to_date_sql,
exp.TableSample: no_tablesample_sql,
exp.TimeStrToUnix: rename_func("UNIX_TIMESTAMP"),
exp.TimeStrToTime: timestrtotime_sql,
exp.TimeToStr: lambda self, e: self.func("DATE_FORMAT", e.this, self.format_time(e)),
exp.Trim: _trim_sql,
exp.TryCast: no_trycast_sql,
Expand Down
1 change: 1 addition & 0 deletions tests/dialects/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ def test_mysql(self):
self.validate_all("CAST(x AS SIGNED INTEGER)", write={"mysql": "CAST(x AS SIGNED)"})
self.validate_all("CAST(x AS UNSIGNED)", write={"mysql": "CAST(x AS UNSIGNED)"})
self.validate_all("CAST(x AS UNSIGNED INTEGER)", write={"mysql": "CAST(x AS UNSIGNED)"})
self.validate_all("TIME_STR_TO_TIME(x)", write={"mysql": "CAST(x AS TIMESTAMP)"})
self.validate_all(
"""SELECT 17 MEMBER OF('[23, "abc", 17, "ab", 10]')""",
write={
Expand Down

0 comments on commit 1ebe49f

Please sign in to comment.