prql icon indicating copy to clipboard operation
prql copied to clipboard

date.trunc generates invalid SQL for SQLite target

Open prql-bot opened this issue 8 months ago • 0 comments

date.trunc was added in #5729 with dialect-specific handling for BigQuery and MSSQL, but lacks an override for SQLite. SQLite does not have a DATE_TRUNC function, so the generic fallback generates invalid SQL:

$ prqlc compile --target sql.sqlite 'from events | select (event_time | date.trunc "day")'
SELECT
  DATE_TRUNC('day', event_time)
FROM
  events

This produces SQL that will fail at runtime on SQLite. Other dialects that lack DATE_TRUNC (like Postgres) correctly return an error for date.diff, establishing a pattern for handling unsupported operations.

Expected behavior: Either generate a SQLite-compatible equivalent (e.g., using strftime or date()) or return a clear error message like date.diff does for unsupported dialects.

Suggested fix: Add a SQLite override in std.sql.prql that either maps to strftime or returns null (to produce an "unsupported" error), similar to how date.diff is handled for Postgres/SQLite.

prql-bot avatar Mar 25 '26 06:03 prql-bot