#8392·sqlglot

MySQL round-trip silently changes semantics: DATE() stripped from DATE_ADD argument

Author: linchangyang-sgCreated Sep 18, 2026Updated Sep 18, 2026

Fully reproducible code snippet Please include a fully reproducible code snippet or the input sql, dialect, and expected output.

print(sqlglot.transpile( "SELECT DATE_ADD(DATE(dt), INTERVAL HOUR(dt) HOUR) FROM t", read="mysql", write="mysql")[0])

output: SELECT DATE_ADD(dt, INTERVAL (HOUR(dt)) HOUR) FROM t expected output: the same as input

So in executing the query, when dt is 2026-09-16T02:23:00, we expect 2026-09-16T02:00:00 however, we got 2026-09-16T04:00:00

I tested versions on 28+, all the same. This has a huge impact on Apache Superset users when using MySQL backend.

Official Documentation MySQL doesn't have date_trunc function, so using date() instead is a common practice. however, in https://github.com/tobymao/sqlglot/blob/main/sqlglot/dialects/dialect.py#L2035, the DATE() was stripped. My suggestion is that if the read dialect == write dialect, no stripping happens.