diff --git a/sqlglot/dialects/exasol.py b/sqlglot/dialects/exasol.py index 0d29fd36b7..452299e400 100644 --- a/sqlglot/dialects/exasol.py +++ b/sqlglot/dialects/exasol.py @@ -198,6 +198,11 @@ class Parser(parser.Parser): **dict.fromkeys(("GROUP_CONCAT", "LISTAGG"), lambda self: self._parse_group_concat()), } + ODBC_DATETIME_LITERALS = { + "d": exp.Date, + "ts": exp.Timestamp, + } + class Generator(generator.Generator): # https://docs.exasol.com/db/latest/sql_references/data_types/datatypedetails.htm#StringDataType STRING_TYPE_MAPPING = { @@ -309,6 +314,10 @@ def datatype_sql(self, expression: exp.DataType) -> str: # https://docs.exasol.com/db/latest/sql/create_view.htm exp.CommentColumnConstraint: lambda self, e: f"COMMENT IS {self.sql(e, 'this')}", exp.WeekOfYear: rename_func("WEEK"), + # https://docs.exasol.com/db/latest/sql_references/functions/alphabeticallistfunctions/to_date.htm + exp.Date: rename_func("TO_DATE"), + # https://docs.exasol.com/db/latest/sql_references/functions/alphabeticallistfunctions/to_timestamp.htm + exp.Timestamp: rename_func("TO_TIMESTAMP"), } def converttimezone_sql(self, expression: exp.ConvertTimezone) -> str: diff --git a/tests/dialects/test_exasol.py b/tests/dialects/test_exasol.py index 3f5de72a9f..daa0015235 100644 --- a/tests/dialects/test_exasol.py +++ b/tests/dialects/test_exasol.py @@ -592,3 +592,9 @@ def test_scalar(self): self.validate_identity( "SELECT name, age, IF age < 18 THEN 'underaged' ELSE 'adult' ENDIF AS LEGALITY FROM persons" ) + + def test_odbc_date_literals(self): + self.validate_identity("SELECT {d'2024-01-01'}", "SELECT TO_DATE('2024-01-01')") + self.validate_identity( + "SELECT {ts'2024-01-01 12:00:00'}", "SELECT TO_TIMESTAMP('2024-01-01 12:00:00')" + )