Repository navigation
docs: document date.trunc's dialect forms and SQLite limitation - #6333
Conversation
prql-bot
left a comment
There was a problem hiding this comment.
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.
The book's
date.truncsection said only "Truncates a date or timestamp to agiven unit", which leaves two things a reader hits in practice undocumented:
DATETRUNC(day, col)andBigQuery emits
DATE_TRUNC(col, DAY)— different function name, differentargument order, unquoted unit — while every other dialect emits
DATE_TRUNC('day', col). That matters when reading the compiled SQL orchecking which units a target accepts.
date.truncthere raisesoperator std.date.trunc is not supported for dialect sqlite(date.trunc generates invalid SQL for SQLite target #5730, fixed infix: date.trunc returns error for SQLite instead of invalid SQL #5733 so it errors rather than emitting invalid SQL), but the page never said
so. The sibling
date.diffsection already carries the equivalent note, addedin docs: document
date.diffin the date functions page #6264.This adds a per-dialect output table and the SQLite note, mirroring how
diffand
noware documented on the same page, plus the cross-reference that theunit 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_operatorgainsgenericandclickhousecases,and
date_trunc_snowflakecovers the one row that doesn't fit that test'sshared template (Snowflake quotes identifiers). SQLite was already covered by
date_trunc_unsupported_dialects.Verification
Each table row was read off
prqlc compileat66d8267, not inferred fromstd.sql.prql:The two dialect forms come from
process_date_truncinprqlc/prqlc/src/sql/gen_expr.rs:216; everything else routes through thegeneric
truncinprqlc/prqlc/src/sql/std.sql.prql:154, which SQLiteoverrides with
nullat line 447.task prqlc:pull-requestpasses exceptqueries::results::read_csv, whichfails in this sandbox because DuckDB can't reach
extensions.duckdb.orgtofetch its
jsonextension — unrelated to this change, and it should pass on CI.cargo insta test -p mdbook-prql(the book's own tests) passes, and prettierreports the page clean.
No
CHANGELOG.mdentry: compiler behavior is unchanged, so there's nothinguser-facing to record beyond the docs themselves.