Skip to content

UNIX_TIMESTAMP is not transpiled from MySQL to other dialects #7754

Description

@danmar2000

UNIX_TIMESTAMP is not being transpiled from MySQL to DuckDB.
It remains UNIX_TIMESTAMP, but I expected it to be converted to EPOCH.

Fully reproducible code snippet

import sqlglot
import duckdb

# UNIX_TIMESTAMP is MySQL-specific; transpiling to DuckDB should produce EPOCH(...)
mysql_sql = "SELECT UNIX_TIMESTAMP(NOW())"
transpiled = sqlglot.transpile(mysql_sql, read="mysql", write="duckdb")[0]
print("Transpiled:", transpiled)

# Try to run the transpiled SQL in DuckDB
duckdb.sql(transpiled)

expected results:

Transpiled: SELECT EPOCH(NOW())

Actual results:

Transpiled: SELECT UNIX_TIMESTAMP(NOW())
Traceback (most recent call last):
  File "/home/marko/repos/a.py", line 10, in <module>
    duckdb.sql(transpiled)
    ~~~~~~~~~~^^^^^^^^^^^^
_duckdb.CatalogException: Catalog Error: Scalar Function with name unix_timestamp does not exist!
Did you mean "to_timestamp"?

Official Documentation
Please include links to official SQL documentation related to your issue.
https://duckdb.org/docs/current/sql/functions/timestamp
https://dev.mysql.com/doc/refman/9.7/en/date-and-time-functions.html#function_unix-timestamp

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions