Skip to content

fix(duckdb)!: LAST_DAY with a WEEK(<day>) part silently returns the last day of the month - #8016

Merged
georgesittas merged 1 commit into
mainfrom
jo/duckdb-last-day-week
Aug 3, 2026
Merged

fix(duckdb)!: LAST_DAY with a WEEK(<day>) part silently returns the last day of the month#8016
georgesittas merged 1 commit into
mainfrom
jo/duckdb-last-day-week

Conversation

@georgesittas

Copy link
Copy Markdown
Collaborator
  • Transpile LAST_DAY week 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)
  • Normalize BigQuery's bare WEEK to WEEK(SUNDAY) at parse time (as DATE_DIFF already does),
    so LAST_DAY(d, WEEK) no longer produces Sunday instead of Saturday
  • Warn on unsupported week parts in dialects whose LAST_DAY only supports months
  • Verified against live BigQuery, Snowflake and DuckDB across a full week of input dates

…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.

This comment was marked as resolved.

@github-actions

Copy link
Copy Markdown
Contributor

SQLGlot Integration Test Results

✅ All tests passed

Comparing:

  • this branch (sqlglot:jo/duckdb-last-day-week @ sqlglot 28c3474)
  • baseline (main @ sqlglot 7784209)

Overall

main: 192411 total, 153555 passed (pass rate: 79.8%)

sqlglot:jo/duckdb-last-day-week: 188349 total, 150251 passed (pass rate: 79.8%)

Transitions:
No change

Dialect pair changes: 0 previous results not found, 1 current results not found

✅ All tests passed

@georgesittas georgesittas changed the title fix(duckdb): LAST_DAY with a WEEK(<day>) part silently returns the last day of the month fix(duckdb)!: LAST_DAY with a WEEK(<day>) part silently returns the last day of the month Aug 1, 2026
@georgesittas
georgesittas merged commit 2856c3e into main Aug 3, 2026
11 checks passed
@georgesittas
georgesittas deleted the jo/duckdb-last-day-week branch August 3, 2026 13:02
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.

3 participants