Skip to content

fix(redshift): transpile TIMESTAMPDIFF to DATEDIFF [CLAUDE]#7902

Closed
chuenchen309 wants to merge 1 commit into
tobymao:mainfrom
chuenchen309:fix/redshift-timestampdiff
Closed

fix(redshift): transpile TIMESTAMPDIFF to DATEDIFF [CLAUDE]#7902
chuenchen309 wants to merge 1 commit into
tobymao:mainfrom
chuenchen309:fix/redshift-timestampdiff

Conversation

@chuenchen309

Copy link
Copy Markdown
Contributor

Problem

TIMESTAMPDIFF transpiled from MySQL to Redshift produces invalid SQL:

sqlglot.transpile("SELECT TIMESTAMPDIFF(SECOND, start_ts, end_ts)", read="mysql", write="redshift")[0]
# -> SELECT TIMESTAMPDIFF(end_ts, start_ts, SECOND)

Redshift has no TIMESTAMPDIFF function, and the arguments come out in raw AST order (the unit last), so the statement fails to run.

Cause

MySQL's TIMESTAMPDIFF parses to exp.TimestampDiff, but RedshiftGenerator.TRANSFORMS had no entry for it, so it fell back to the default function rendering.

Fix

Redshift already renders the sibling exp.DateDiff with date_delta_sql("DATEDIFF"). Wiring exp.TimestampDiff to the same handler produces DATEDIFF(unit, start, end), which matches Redshift's builtin and preserves the end - start semantics.

# -> SELECT DATEDIFF(SECOND, start_ts, end_ts)

Testing

Added a read-direction case in test_redshift.py (fails on main, passes here). tests/dialects/ full suite: 748 passed, no regressions. ruff check / ruff format clean.

Disclosure: authored by an AI coding agent (Claude Code) on my account — it found the bug, ran the repro, wrote the test and this description. I review every change and am accountable for it; the verification is real and re-runnable from the diff.

Redshift has no TIMESTAMPDIFF function, so transpiling MySQL's
TIMESTAMPDIFF(unit, a, b) to Redshift emitted an invalid call with the
arguments in raw AST order, TIMESTAMPDIFF(b, a, unit). Redshift already
renders the sibling exp.DateDiff via date_delta_sql("DATEDIFF"); wire
exp.TimestampDiff to the same handler so it becomes DATEDIFF(unit, a, b).

Co-authored-by AI: Claude (Claude Code). [CLAUDE]
@georgesittas georgesittas self-assigned this Jul 20, 2026
@georgesittas

Copy link
Copy Markdown
Collaborator

Given the previous PRs, I don't trust that this has been tested against the engines for semantic equivalency. Therefore, I'm closing this.

@chuenchen309 some of the other PRs were easy/quick to review and we thank you for them. But, given our team's bandwidth, we won't be spending time reviewing these Claude-generated PRs moving forward, because the quality is not up to expectations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants