Skip to content

feat: add 'date.trunc' function for date trunc support#5729

Merged
max-sixty merged 6 commits intoPRQL:mainfrom
AhnLab-OSSG:feature/datetrunc
Mar 25, 2026
Merged

feat: add 'date.trunc' function for date trunc support#5729
max-sixty merged 6 commits intoPRQL:mainfrom
AhnLab-OSSG:feature/datetrunc

Conversation

@sunyeongchoi
Copy link
Copy Markdown
Contributor

Closes #5728

Adds a date.trunc function to provide native date truncation capabilities in PRQL.

derive {
  order_day = (order_date | date.trunc 'day'),
  start_of_month = (@2026-03-24 | date.trunc 'month')
}

@max-sixty
Copy link
Copy Markdown
Member

great, would you mind running pre-commit run -a to fix the whitespace

the other CI failure is on me; I will fix


more generally: thank you for these. Sorry the diffs are so big when something is added to the stdlib. if you want to bundle the changes together, that's fine (but no obligation, fine with me)

Copy link
Copy Markdown
Collaborator

@prql-bot prql-bot left a comment

Choose a reason for hiding this comment

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

The BigQuery and MSSQL date.trunc s-string overrides in std.sql.prql (lines 233 and 315) are dead code — process_date_trunc in gen_expr.rs intercepts these dialects and constructs the AST directly before the s-strings are ever reached. The s-strings would also produce incorrect SQL (quoted unit strings instead of unquoted keywords), which is why the Rust code is needed. Consider removing the BigQuery/MSSQL overrides to avoid confusion, or adding a comment noting they're overridden.

Minor: SQLite has no date.trunc override (unlike date.diff which has -> null), so date.trunc on SQLite will generate DATE_TRUNC(...) which SQLite doesn't support. Fine as a follow-up.

@sunyeongchoi
Copy link
Copy Markdown
Contributor Author

great, would you mind running pre-commit run -a to fix the whitespace

the other CI failure is on me; I will fix

more generally: thank you for these. Sorry the diffs are so big when something is added to the stdlib. if you want to bundle the changes together, that's fine (but no obligation, fine with me)

I ran pre-commit as you suggested. Thank you! Regarding your comment, 'if you want to bundle the changes together, that's fine'—does that mean I can submit the main logic changes first without the snap file updates, and then update the snap files in a separate PR later?

@max-sixty
Copy link
Copy Markdown
Member

does that mean I can submit the main logic changes first without the snap file updates, and then update the snap files in a separate PR later?

unfortunately not — I had meant if you want to put multiple functions in the same PR...

@max-sixty max-sixty merged commit 82cf74b into PRQL:main Mar 25, 2026
39 checks passed
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.

[Feature Request] Support native date.trunc function in standard library to reduce S-string usage

3 participants