Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions sqlglot/dialects/exasol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions tests/dialects/test_exasol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')"
)