Skip to content

Feature Request: Please add .commands support for DuckDB dialect #939

Open

Description

@pavlokurochka

Describe the Feature
Currently .commands break formatting of DuckDB SQL files

Why do you want this feature?
It'll be much more convenient not to have to comment them out to be able to format.

Activity

  1. nene commented on Apr 11, 2026

    @nene
    Collaborator

    This is currently in similar vein to how \commands in PostgreSQL are not supported. And I guess there are other dialects with similar special command-line commands.

    Looks like this page documents the DuckDB syntax for these commands.

    Because DuckDB commands begin with a . it's particularly tricky to support because . is already a special symbol in SQL. Even . at the beginning of a line is perfectly valid SQL. So I need to somehow understand when dot at the beginning of a line is inside an SQL expression, like:

    SELECT tbl
    .help
    FROM tbl;

    Versus when it's not inside an SQL expression:

    SELECT tbl;
    .help

    Ideally I'd like to distinguish this at the Lexer level, but because of the above, that's not possible. So I would need to do this inside the parser, but until now the parser has been completely dialect-agnostic. I'm not really keen to add such a conditional logic (if DuckDB, parse it differently) in there.

    Hmm... possibly I can do a separate pass over the tokens (like I already do for some dialects) to distinguish between the different uses of . before passing it to parser.

    In any case, solving the \command problem in PostgreSQL is currently with a higher priority.

  2. pinned and unpinned a comment on Apr 11, 2026
  3. pavlokurochka commented on Apr 27, 2026

    @pavlokurochka
    Author

    So far figured out a workaround - I wrap .commands in comments like this:

       /* sql-formatter-disable */
    .echo ON
    .timer on
      /* sql-formatter-enable */
    
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions