Skip to content

--no-headers doesn't work on most formats #566

Closed

Description

@zellyn

Version 3.33

sqlite-utils query library.db 'select asin from audible' --fmt plain --no-headers | head -3
asin
0062804006
0062891421

Activity

  1. simonw commented on Jul 9, 2023

    @simonw
    Owner

    Thanks, looks like a bug.

  2. simonw commented on Jul 9, 2023

    @simonw
    Owner

    On consulting https://pypi.org/project/tabulate/ it looks like most of those formats don't actually makes sense without headers - so the right thing here might be to raise an error if --fmt and --no-headers are used at the same time.

  3. tobych commented on Apr 29, 2024

    @tobych

    Seems to me that this is not a bug, and that @zellyn might be misunderstanding what --no-headers is for.

    The help text for --no-headers reads: "Omit CSV headers".

    (Well, it applies to TSV files, too. So the help text could be improved.)

    I reckon raising an error if --no-header is used without either --csv or --tsv would be good.

    Furthermore, the options seem a bit messy to me. I mean, you could specify --csv, --tsv, and --fmt all at once. I'd suggest at least check that none of that is happening. And make it clear in the help text that --fmt is using the tabulate library. Don't try to hide it: that abstraction is leaking already.

  4. zellyn commented on Apr 29, 2024

    @zellyn
    Author

    My use case for using --no-headers is almost 100% “I'm about to pass this through xargs or some other unix utility.

    But you're right that it doesn't make sense for most of the formats that are generating some kind of markup rendering.

  5. tobych commented on Apr 29, 2024

    @tobych

    @zellyn Which formats are you working with? I've not looked closely at the list of formats tabulate can write, and which have headers. Are you trying to skip headers from a format that sqlite-utils is delegating to tabulate for? Perhaps the tabulate library has an option for omitting a header: sqlite-utils could pass that (or arbitrary) options to tabulate.

    Do bear in mind that if you're using a system that has the tail command, you can use tail -n +2 as a filter to remove the first line of a text stream:

    $ printf "1\n2\n3\n" | tail -n +2
    2
    3
  6. zellyn commented on Apr 30, 2024

    @zellyn
    Author

    Yeah, I've done the tail thing for sure. I've mostly gotten around this now by using tsv and only selecting one column, which basically is plain.

  7. CrepuscularIRIS commented on Apr 15, 2026

    @CrepuscularIRIS

    Hi — I'd like to work on this.

    The root cause is that the two tabulate.tabulate() call sites in cli.py (the tables command at line 240 and _execute_query at line 2142) always pass headers=headers regardless of the --no-headers flag. The flag is only checked in the CSV/TSV branch.

    Rather than raising an error when --fmt and --no-headers are combined, I found that tabulate.tabulate(data, headers=()) cleanly suppresses headers while preserving the table format. This approach makes --no-headers work consistently across all output modes (CSV, TSV, and tabulate formats).

    I have a fix with tests ready — would this be welcome as a PR?

  8. added a commit that references this issue on Apr 15, 2026
    2786dcb
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

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions