Repository navigation
Description
The date-specifier table in web/book/src/reference/stdlib/date.md lists %k under "the list of the specifiers currently supported", but every dialect rejects it:
$ printf 'prql target:sql.postgres\nfrom tbl\nselect {a = (tbl.col | date.to_text "%%k")}\n' | prqlc compile
Error:
╭─[ :3:37 ]
│
3 │ select {a = (tbl.col | date.to_text "%k")}
│ ──┬─
│ ╰─── PRQL doesn't support this format specifier
───╯
Same error on sql.mysql. The mechanism: chrono parses %k (and %_H) as Item::Numeric(Numeric::Hour, Pad::Space), and no dialect's translate_chrono_item in prqlc/prqlc/src/sql/dialect.rs has a Pad::Space arm — the only Pad::Space mentions in the file are the reverse-mapping helper at L29 and two unit tests. Pad::None and Pad::Zero are handled everywhere, so %-H, %H, %-d, %d etc. all work; every space-padded specifier falls through to the unsupported-specifier error.
Two ways to resolve it, and which one is right is a maintainer call:
- Docs fix — drop the
%krow from the supported table (or move it to a "not supported" note). Cheapest, and makes the table accurate today. Worth pairing with adding a%-Hrow, which is supported (TO_CHAR(col, 'FMHH24')on Postgres) but isn't documented, even though the sibling%-mand%-drows are. - Implement it — add
Pad::Spacearms to the dialect handlers. No target has a direct space-padding template: Postgres would need something likeLPAD(TO_CHAR(col, 'FMHH24'), 2, ' ')rather than a plain format string, and MySQL's own%kis the no-pad hour (already used forPad::Noneat L547), so it isn't a one-line addition.
Found while reviewing #6138, which fixes a separate wrong example in the same table; left out of that PR since it needs the decision above.
Sweep of the rest of the table against sql.postgres
%k is the only failing row; the other 27 specifiers all compile.
%Y TO_CHAR(col, 'YYYY') %H TO_CHAR(col, 'HH24')
%y TO_CHAR(col, 'YY') %k ERROR — unsupported
%m TO_CHAR(col, 'MM') %I TO_CHAR(col, 'HH12')
%-m TO_CHAR(col, 'FMMM') %p TO_CHAR(col, 'AM')
%b TO_CHAR(col, 'Mon') %M TO_CHAR(col, 'MI')
%B TO_CHAR(col, 'FMMonth') %S TO_CHAR(col, 'SS')
%d TO_CHAR(col, 'DD') %f TO_CHAR(col, 'US')
%-d TO_CHAR(col, 'FMDD') %R TO_CHAR(col, 'HH24:MI')
%a TO_CHAR(col, 'Dy') %T TO_CHAR(col, 'HH24:MI:SS')
%A TO_CHAR(col, 'FMDay') %X TO_CHAR(col, 'HH24:MI:SS')
%D TO_CHAR(col, 'MM/DD/YY') %r TO_CHAR(col, 'HH12:MI:SS AM')
%x TO_CHAR(col, 'MM/DD/YY') %+ TO_CHAR(col, 'YYYY-MM-DD"T"HH24:MI:SS.USZ')
%F TO_CHAR(col, 'YYYY-MM-DD') %t %n %% literals
Activity
prql-bot commentedon Aug 4, 2026
Took the docs route in #6140 — implementing
Pad::Spaceneeds a per-dialect design decision (Postgres has no space-padding format template, MySQL's%kalready means the no-pad hour), whereas the table is wrong today either way. The%krow is dropped, replaced with the%-Hrow that was missing, and a line under the table notes that space-padded specifiers aren't supported by any dialect.The durable part is a new
test_date_format_specifiers_compilein the book documentation tests: it parses the specifier table out ofdate.mdand compiles each row againstsql.postgres, so the table can't drift fromtranslate_chrono_itemagain. It fails onmainwith exactly one error (%k), which matches the sweep above.If implementing space padding is preferred instead, the test makes that easy to check — re-adding the
%krow is the assertion.