Skip to content

Commit

Permalink
Fix(clickhouse): generate formatDateTime instead of DATE_FORMAT fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesittas committed Sep 10, 2024
1 parent e1f6ae3 commit cb5bcff
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion sqlglot/dialects/clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ class Generator(generator.Generator):
"position", e.this, e.args.get("substr"), e.args.get("position")
),
exp.TimeToStr: lambda self, e: self.func(
"DATE_FORMAT", e.this, self.format_time(e), e.args.get("zone")
"formatDateTime", e.this, self.format_time(e), e.args.get("zone")
),
exp.TimeStrToTime: _timestrtotime_sql,
exp.TimestampAdd: _datetime_delta_sql("TIMESTAMP_ADD"),
Expand Down
6 changes: 3 additions & 3 deletions tests/dialects/test_clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,15 +470,15 @@ def test_clickhouse(self):
self.validate_identity("SELECT FORMAT")
self.validate_identity("1 AS FORMAT").assert_is(exp.Alias)

self.validate_identity("SELECT DATE_FORMAT(NOW(), '%Y-%m-%d', '%T')")
self.validate_identity("SELECT formatDateTime(NOW(), '%Y-%m-%d', '%T')")
self.validate_all(
"SELECT DATE_FORMAT(NOW(), '%Y-%m-%d')",
"SELECT formatDateTime(NOW(), '%Y-%m-%d')",
read={
"clickhouse": "SELECT formatDateTime(NOW(), '%Y-%m-%d')",
"mysql": "SELECT DATE_FORMAT(NOW(), '%Y-%m-%d')",
},
write={
"clickhouse": "SELECT DATE_FORMAT(NOW(), '%Y-%m-%d')",
"clickhouse": "SELECT formatDateTime(NOW(), '%Y-%m-%d')",
"mysql": "SELECT DATE_FORMAT(NOW(), '%Y-%m-%d')",
},
)
Expand Down

0 comments on commit cb5bcff

Please sign in to comment.