diff options
Diffstat (limited to 'sqlglot/dialects/mysql.py')
-rw-r--r-- | sqlglot/dialects/mysql.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/sqlglot/dialects/mysql.py b/sqlglot/dialects/mysql.py index c2c2c8c..235eb77 100644 --- a/sqlglot/dialects/mysql.py +++ b/sqlglot/dialects/mysql.py @@ -8,6 +8,7 @@ from sqlglot.dialects.dialect import ( no_paren_current_date_sql, no_tablesample_sql, no_trycast_sql, + rename_func, strposition_to_locate_sql, ) from sqlglot.helper import seq_get @@ -22,9 +23,8 @@ def _show_parser(*args, **kwargs): def _date_trunc_sql(self, expression): - unit = expression.name.lower() - - expr = self.sql(expression.expression) + expr = self.sql(expression, "this") + unit = expression.text("unit") if unit == "day": return f"DATE({expr})" @@ -42,7 +42,7 @@ def _date_trunc_sql(self, expression): concat = f"CONCAT(YEAR({expr}), ' 1 1')" date_format = "%Y %c %e" else: - self.unsupported("Unexpected interval unit: {unit}") + self.unsupported(f"Unexpected interval unit: {unit}") return f"DATE({expr})" return f"STR_TO_DATE({concat}, '{date_format}')" @@ -443,6 +443,10 @@ class MySQL(Dialect): exp.DateAdd: _date_add_sql("ADD"), exp.DateSub: _date_add_sql("SUB"), exp.DateTrunc: _date_trunc_sql, + exp.DayOfWeek: rename_func("DAYOFWEEK"), + exp.DayOfMonth: rename_func("DAYOFMONTH"), + exp.DayOfYear: rename_func("DAYOFYEAR"), + exp.WeekOfYear: rename_func("WEEKOFYEAR"), exp.GroupConcat: lambda self, e: f"""GROUP_CONCAT({self.sql(e, "this")} SEPARATOR {self.sql(e, "separator") or "','"})""", exp.StrToDate: _str_to_date_sql, exp.StrToTime: _str_to_date_sql, |