Skip to content

Commit

Permalink
fix(presto): datetime -> timestamp (#2113)
Browse files Browse the repository at this point in the history
* fix(presto): datetime -> timestamp

* Fixup
  • Loading branch information
barakalon authored Aug 25, 2023
1 parent 25cd414 commit 0316f7f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions sqlglot/dialects/presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ class Generator(generator.Generator):
exp.DataType.Type.TIMETZ: "TIME",
exp.DataType.Type.TIMESTAMPTZ: "TIMESTAMP",
exp.DataType.Type.STRUCT: "ROW",
exp.DataType.Type.DATETIME: "TIMESTAMP",
exp.DataType.Type.DATETIME64: "TIMESTAMP",
}

TRANSFORMS = {
Expand Down
3 changes: 2 additions & 1 deletion tests/dialects/test_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ def validate_all(self, sql, read=None, write=None, pretty=False, identify=False)
Args:
sql (str): Main SQL expression
dialect (str): dialect of `sql`
read (dict): Mapping of dialect -> SQL
write (dict): Mapping of dialect -> SQL
pretty (bool): prettify both read and write
identify (bool): quote identifiers in both read and write
"""
expression = self.parse_one(sql)

Expand Down
5 changes: 5 additions & 0 deletions tests/dialects/test_presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ def test_time(self):
"presto": "SELECT CAST('2012-10-31 00:00' AS TIMESTAMP) AT TIME ZONE 'America/Sao_Paulo'",
},
)
self.validate_all(
"CAST(x AS TIMESTAMP)",
write={"presto": "CAST(x AS TIMESTAMP)"},
read={"mysql": "CAST(x AS DATETIME)", "clickhouse": "CAST(x AS DATETIME64)"},
)

def test_ddl(self):
self.validate_all(
Expand Down

0 comments on commit 0316f7f

Please sign in to comment.