fix(duckdb)!: LAST_DAY with a WEEK(<day>) part silently returns the last day of the month - #8016
Merged
Merged
Conversation
…st day of the month
_last_day_sql read the unit via expression.text("unit"), which returns ''
for BigQuery's WeekStart node, so LAST_DAY(d, WEEK(SUNDAY)) fell into the
MONTH default and emitted a plain LAST_DAY(d) with no warning, e.g.
2008-11-30 instead of 2008-11-15 for LAST_DAY(DATE '2008-11-10', WEEK(SUNDAY)).
The week branch is generalized to any start day (the old Snowflake
formula is the start-day-Monday case and its output is unchanged), which
also makes ISOWEEK work instead of warning. The generic lastday_sql now
warns for WeekStart units instead of silently dropping them.
georgesittas
requested review from
Copilot,
fivetran-kwoodbeck,
geooo109 and
treysp
July 31, 2026 23:21
Contributor
SQLGlot Integration Test Results✅ All tests passedComparing: Overallmain: 192411 total, 153555 passed (pass rate: 79.8%) sqlglot:jo/duckdb-last-day-week: 188349 total, 150251 passed (pass rate: 79.8%) Transitions: Dialect pair changes: 0 previous results not found, 1 current results not found ✅ All tests passed |
geooo109
approved these changes
Aug 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
LAST_DAYweek units to DuckDB using the source dialect's week start day,instead of always assuming Monday-start weeks (e.g. BigQuery's
WEEK(SUNDAY),ISOWEEK)WEEKtoWEEK(SUNDAY)at parse time (asDATE_DIFFalready does),so
LAST_DAY(d, WEEK)no longer produces Sunday instead of SaturdayLAST_DAYonly supports months