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
6 changes: 5 additions & 1 deletion sqlglot/dialects/exasol.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
build_date_delta,
no_last_day_sql,
DATE_ADD_OR_SUB,
build_timetostr_or_tochar,
)
from sqlglot.generator import unsupported_args
from sqlglot.helper import seq_get
Expand Down Expand Up @@ -368,7 +369,7 @@ class Parser(parser.Parser):
"TRUNCATE": _build_trunc,
"VAR_POP": exp.VariancePop.from_arg_list,
"APPROXIMATE_COUNT_DISTINCT": exp.ApproxDistinct.from_arg_list,
"TO_CHAR": build_formatted_time(exp.ToChar, "exasol"),
"TO_CHAR": build_timetostr_or_tochar,
"TO_DATE": build_formatted_time(exp.TsOrDsToDate, "exasol"),
# https://docs.exasol.com/db/latest/sql_references/functions/alphabeticallistfunctions/convert_tz.htm
"CONVERT_TZ": lambda args: exp.ConvertTimezone(
Expand Down Expand Up @@ -438,6 +439,9 @@ class Generator(generator.Generator):
exp.DataType.Type.DECIMAL128: "DECIMAL",
exp.DataType.Type.DECIMAL256: "DECIMAL",
exp.DataType.Type.DATETIME: "TIMESTAMP",
exp.DataType.Type.TIMESTAMPTZ: "TIMESTAMP",
exp.DataType.Type.TIMESTAMPLTZ: "TIMESTAMP",
exp.DataType.Type.TIMESTAMPNTZ: "TIMESTAMP",
}

def datatype_sql(self, expression: exp.DataType) -> str:
Expand Down
12 changes: 11 additions & 1 deletion tests/dialects/test_exasol.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,16 @@ def test_datetime_functions(self):
f"SELECT TO_CHAR(CAST('2024-07-08 13:45:00' AS TIMESTAMP), '{fmt}') AS {alias}"
)

self.validate_all(
"SELECT TO_CHAR(CAST('2024-07-08 13:45:00' AS TIMESTAMP), 'DY')",
write={
"exasol": "SELECT TO_CHAR(CAST('2024-07-08 13:45:00' AS TIMESTAMP), 'DY')",
"oracle": "SELECT TO_CHAR(CAST('2024-07-08 13:45:00' AS TIMESTAMP), 'DY')",
"postgres": "SELECT TO_CHAR(CAST('2024-07-08 13:45:00' AS TIMESTAMP), 'TMDy')",
"databricks": "SELECT DATE_FORMAT(CAST('2024-07-08 13:45:00' AS TIMESTAMP), 'EEE')",
},
)

self.validate_all(
"TO_DATE(x, 'YYYY-MM-DD')",
write={
Expand Down Expand Up @@ -481,7 +491,7 @@ def test_datetime_functions(self):
)
units = ["MM", "QUARTER", "WEEK", "MINUTE", "YEAR"]
for unit in units:
with self.subTest(f"Testing TO_CHAR with format '{unit}'"):
with self.subTest(f"Testing DATE_TRUNC with format '{unit}'"):
self.validate_all(
f"SELECT TRUNC(CAST('2006-12-31' AS DATE), '{unit}') AS TRUNC",
write={
Expand Down