From ecdbb3ecf6a722059836ab949759795e3fa7b775 Mon Sep 17 00:00:00 2001 From: Nnamdi Nwabuokei Date: Tue, 11 Nov 2025 22:32:32 +0100 Subject: [PATCH 1/2] chore(exasol): implemented odbc date time literal --- sqlglot/dialects/exasol.py | 9 +++++++++ tests/dialects/test_exasol.py | 14 ++++++++++++++ 2 files changed, 23 insertions(+) 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..7413c758cb 100644 --- a/tests/dialects/test_exasol.py +++ b/tests/dialects/test_exasol.py @@ -1,4 +1,5 @@ from tests.dialects.test_dialect import Validator +from sqlglot import exp class TestExasol(Validator): @@ -592,3 +593,16 @@ 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): + for read, write in [ + ("{d'2024-01-01'}", "TO_DATE('2024-01-01')"), + ("{ts'2024-01-01 12:00:00'}", "TO_TIMESTAMP('2024-01-01 12:00:00')"), + ]: + with self.subTest(f"Testing ODBC date literal: {read}"): + read_sql = f"SELECT {read}" + write_sql = f"SELECT {write}" + + expr = self.parse_one(read_sql) + self.assertIsInstance(expr, exp.Select) + self.validate_identity(read_sql, write_sql) From ca47e24272c745de85c78f79bbb648efac55fdda Mon Sep 17 00:00:00 2001 From: Nnamdi Nwabuokei Date: Wed, 12 Nov 2025 13:20:52 +0100 Subject: [PATCH 2/2] chore(exasol): refactored test --- tests/dialects/test_exasol.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/tests/dialects/test_exasol.py b/tests/dialects/test_exasol.py index 7413c758cb..daa0015235 100644 --- a/tests/dialects/test_exasol.py +++ b/tests/dialects/test_exasol.py @@ -1,5 +1,4 @@ from tests.dialects.test_dialect import Validator -from sqlglot import exp class TestExasol(Validator): @@ -595,14 +594,7 @@ def test_scalar(self): ) def test_odbc_date_literals(self): - for read, write in [ - ("{d'2024-01-01'}", "TO_DATE('2024-01-01')"), - ("{ts'2024-01-01 12:00:00'}", "TO_TIMESTAMP('2024-01-01 12:00:00')"), - ]: - with self.subTest(f"Testing ODBC date literal: {read}"): - read_sql = f"SELECT {read}" - write_sql = f"SELECT {write}" - - expr = self.parse_one(read_sql) - self.assertIsInstance(expr, exp.Select) - self.validate_identity(read_sql, write_sql) + 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')" + )