Skip to content

Commit b0afbac

Browse files
authored
fix(exasol): fix TO_CHAR parsing leaking canonical datetime format tokens (#6650)
* fix(exasol): fix TO_CHAR parsing leaking canonical datetime format tokens * chore(exasol): removed unused test
1 parent 2fa29b1 commit b0afbac

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

sqlglot/dialects/exasol.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
build_date_delta,
1717
no_last_day_sql,
1818
DATE_ADD_OR_SUB,
19+
build_timetostr_or_tochar,
1920
)
2021
from sqlglot.generator import unsupported_args
2122
from sqlglot.helper import seq_get
@@ -368,7 +369,7 @@ class Parser(parser.Parser):
368369
"TRUNCATE": _build_trunc,
369370
"VAR_POP": exp.VariancePop.from_arg_list,
370371
"APPROXIMATE_COUNT_DISTINCT": exp.ApproxDistinct.from_arg_list,
371-
"TO_CHAR": build_formatted_time(exp.ToChar, "exasol"),
372+
"TO_CHAR": build_timetostr_or_tochar,
372373
"TO_DATE": build_formatted_time(exp.TsOrDsToDate, "exasol"),
373374
# https://docs.exasol.com/db/latest/sql_references/functions/alphabeticallistfunctions/convert_tz.htm
374375
"CONVERT_TZ": lambda args: exp.ConvertTimezone(
@@ -438,6 +439,9 @@ class Generator(generator.Generator):
438439
exp.DataType.Type.DECIMAL128: "DECIMAL",
439440
exp.DataType.Type.DECIMAL256: "DECIMAL",
440441
exp.DataType.Type.DATETIME: "TIMESTAMP",
442+
exp.DataType.Type.TIMESTAMPTZ: "TIMESTAMP",
443+
exp.DataType.Type.TIMESTAMPLTZ: "TIMESTAMP",
444+
exp.DataType.Type.TIMESTAMPNTZ: "TIMESTAMP",
441445
}
442446

443447
def datatype_sql(self, expression: exp.DataType) -> str:

tests/dialects/test_exasol.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,16 @@ def test_datetime_functions(self):
423423
f"SELECT TO_CHAR(CAST('2024-07-08 13:45:00' AS TIMESTAMP), '{fmt}') AS {alias}"
424424
)
425425

426+
self.validate_all(
427+
"SELECT TO_CHAR(CAST('2024-07-08 13:45:00' AS TIMESTAMP), 'DY')",
428+
write={
429+
"exasol": "SELECT TO_CHAR(CAST('2024-07-08 13:45:00' AS TIMESTAMP), 'DY')",
430+
"oracle": "SELECT TO_CHAR(CAST('2024-07-08 13:45:00' AS TIMESTAMP), 'DY')",
431+
"postgres": "SELECT TO_CHAR(CAST('2024-07-08 13:45:00' AS TIMESTAMP), 'TMDy')",
432+
"databricks": "SELECT DATE_FORMAT(CAST('2024-07-08 13:45:00' AS TIMESTAMP), 'EEE')",
433+
},
434+
)
435+
426436
self.validate_all(
427437
"TO_DATE(x, 'YYYY-MM-DD')",
428438
write={
@@ -481,7 +491,7 @@ def test_datetime_functions(self):
481491
)
482492
units = ["MM", "QUARTER", "WEEK", "MINUTE", "YEAR"]
483493
for unit in units:
484-
with self.subTest(f"Testing TO_CHAR with format '{unit}'"):
494+
with self.subTest(f"Testing DATE_TRUNC with format '{unit}'"):
485495
self.validate_all(
486496
f"SELECT TRUNC(CAST('2006-12-31' AS DATE), '{unit}') AS TRUNC",
487497
write={

0 commit comments

Comments
 (0)