Skip to content

fix: datetime_diff transpilation bigquery to duckdb - #6126

Merged
toriwei merged 2 commits into
mainfrom
fix/datetime-diff-bigquery
Oct 16, 2025
Merged

toriwei merged 2 commits into
mainfrom
fix/datetime-diff-bigquery

Conversation

@toriwei

@toriwei toriwei commented Oct 16, 2025 •

Copy link
Copy Markdown
Collaborator

fixes: #6107

@georgesittas georgesittas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be good to go after removing that line in bigquery.py.

Comment thread sqlglot/dialects/bigquery.py Resolved
@toriwei
toriwei merged commit 8744431 into main Oct 16, 2025
@toriwei
toriwei deleted the fix/datetime-diff-bigquery branch October 16, 2025 21:32
fresioAS pushed a commit to fresioAS/sqlglot that referenced this pull request May 3, 2026
georgesittas added a commit that referenced this pull request Jul 20, 2026
…no [CLAUDE] (#7895)

* Fix TIMESTAMP_DIFF/DATETIME_DIFF transpilation to Presto/Trino [CLAUDE]

Presto and Trino only have date_diff(unit, ts1, ts2); they have no
TIMESTAMPDIFF, DATETIME_DIFF or TIMESTAMP_DIFF. sqlglot maps exp.DateDiff
to DATE_DIFF for Presto, but exp.TimestampDiff and exp.DatetimeDiff
(produced by e.g. BigQuery TIMESTAMP_DIFF/DATETIME_DIFF) had no
Presto/Trino handler and fell through to the generic function fallback,
emitting the node name verbatim with the unit-last arg order - invalid,
unparseable SQL.

Route all three diff nodes through DATE_DIFF(unit, expression, this) for
Presto (Trino inherits it). date_diff(unit, ts1, ts2) = ts2 - ts1, so
(expression, this) preserves the source's a - b semantics, matching what
DATE_DIFF and DuckDB already produce (cf. merged #6126, #4334).

* Update tests/dialects/test_bigquery.py

---------

Co-authored-by: Jo <[email protected]>
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.

DATETIME_DIFF is not transpiled correctly from BigQuery to DuckDB

2 participants