Skip to content

Docs list %k as a supported date.to_text specifier, but every dialect rejects it #6139

Closed

Description

@prql-bot

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:

  1. Docs fix — drop the %k row from the supported table (or move it to a "not supported" note). Cheapest, and makes the table accurate today. Worth pairing with adding a %-H row, which is supported (TO_CHAR(col, 'FMHH24') on Postgres) but isn't documented, even though the sibling %-m and %-d rows are.
  2. Implement it — add Pad::Space arms to the dialect handlers. No target has a direct space-padding template: Postgres would need something like LPAD(TO_CHAR(col, 'FMHH24'), 2, ' ') rather than a plain format string, and MySQL's own %k is the no-pad hour (already used for Pad::None at 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

  1. prql-bot commented on Aug 4, 2026

    @prql-bot
    CollaboratorAuthor

    Took the docs route in #6140 — implementing Pad::Space needs a per-dialect design decision (Postgres has no space-padding format template, MySQL's %k already means the no-pad hour), whereas the table is wrong today either way. The %k row is dropped, replaced with the %-H row 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_compile in the book documentation tests: it parses the specifier table out of date.md and compiles each row against sql.postgres, so the table can't drift from translate_chrono_item again. It fails on main with 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 %k row is the assertion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions