Skip to content

docs: document date.trunc's dialect forms and SQLite limitation - #6333

Merged
max-sixty merged 2 commits into
mainfrom
docs/date-trunc-dialects
Sep 18, 2026
Merged

max-sixty merged 2 commits into
mainfrom
docs/date-trunc-dialects

Conversation

@prql-bot

Copy link
Copy Markdown
Collaborator

The book's date.trunc section said only "Truncates a date or timestamp to a
given unit", which leaves two things a reader hits in practice undocumented:

This adds a per-dialect output table and the SQLite note, mirroring how diff
and now are documented on the same page, plus the cross-reference that the
unit is a string here and a bare keyword for date.diff.

Every row of the new table is now covered by a test, so the page can't drift
from the compiler: date_trunc_operator gains generic and clickhouse cases,
and date_trunc_snowflake covers the one row that doesn't fit that test's
shared template (Snowflake quotes identifiers). SQLite was already covered by
date_trunc_unsupported_dialects.

Verification

Each table row was read off prqlc compile at 66d8267, not inferred from
std.sql.prql:

generic     SELECT DATE_TRUNC('day', event_time) FROM events
duckdb      SELECT DATE_TRUNC('day', event_time) FROM events
postgres    SELECT DATE_TRUNC('day', event_time) FROM events
mysql       SELECT DATE_TRUNC('day', event_time) FROM events
clickhouse  SELECT DATE_TRUNC('day', event_time) FROM events
snowflake   SELECT DATE_TRUNC('day', "event_time") FROM "events"
mssql       SELECT DATETRUNC(day, event_time) FROM events
bigquery    SELECT DATE_TRUNC(event_time, DAY) FROM events
sqlite      Error: operator std.date.trunc is not supported for dialect sqlite

The two dialect forms come from process_date_trunc in
prqlc/prqlc/src/sql/gen_expr.rs:216; everything else routes through the
generic trunc in prqlc/prqlc/src/sql/std.sql.prql:154, which SQLite
overrides with null at line 447.

task prqlc:pull-request passes except queries::results::read_csv, which
fails in this sandbox because DuckDB can't reach extensions.duckdb.org to
fetch its json extension — unrelated to this change, and it should pass on CI.
cargo insta test -p mdbook-prql (the book's own tests) passes, and prettier
reports the page clean.

No CHANGELOG.md entry: compiler behavior is unchanged, so there's nothing
user-facing to record beyond the docs themselves.

@prql-bot prql-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The new sentence on how the unit is written stops one step short of what the compiler enforces: date.trunc requires a string literal, not any text value. Piping a unit column through it — which "written as a string" reads as permitted — fails with `std.date.trunc` only supports a string literal as unit (pinned by error_messages::date_trunc_with_column_unit), and the page gives no hint why. That's the same class of gap this PR set out to close, so it belongs in the same sentence.

Smaller: the guardrail comment on date_trunc_operator says each row of the table needs a case there, but the Snowflake row's case is date_trunc_snowflake. A contributor adding a dialect that quotes identifiers — Oracle emits the Snowflake form — follows the comment into a template that can't hold it.

Comment thread web/book/src/reference/stdlib/date.md Resolved
Comment thread prqlc/prqlc/tests/integration/sql.rs Resolved
@max-sixty
max-sixty merged commit c5daab6 into main Sep 18, 2026
36 checks passed
@max-sixty
max-sixty deleted the docs/date-trunc-dialects branch September 18, 2026 18:17
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