Skip to content

rtk psql parses psql's aligned table output without -X, so a user's ~/.psqlrc silently changes what rtk reads #3395

Open

Description

@HetCreep

rtk psql parses psql's human-readable aligned table — | column separators, ^[-+]+$ rules, and a (N rows) footer — but it does not pass -X, so psql still executes the user's ~/.psqlrc first. Any \pset in there changes the format rtk is parsing.

Provenance: AI-assisted source audit, human-directed, at v0.44.2 (700bdde). Source read only — psql is not installed on this machine, so I have not run the failing cases.

Source

  • src/cmds/cloud/psql_cmd.rs:29-45 (run) builds the command and injects no flags.
  • :111 and :19/:63 implement the parse: is_table_format looks for the | separator and the [-+]+ rule line, and the summary keys off (N rows).

What breaks it

  1. ~/.psqlrc is honoured. \pset border 0 or \pset border 2, \pset format wrapped|csv|html, \pset fieldsep, or \pset linestyle unicode all change the output shape. linestyle unicode emits │ and ─ instead of | and -, so is_table_format stops recognising the output as a table at all.
  2. (N rows) is translated. It goes through NLS, so on a server or client with a non-English lc_messages the footer text differs and the row-count summary misses.
  3. A literal | inside a cell shifts the columns. The parse splits the line on |, so a value containing a pipe produces an extra column — the row is rendered with fields shifted rather than failing to parse. That is the case I would worry about most: a wrong answer rather than a fallback.

Suggested directions (untested — no programmer has reviewed these)

psql documents machine-readable modes that do not depend on user configuration:

  • --csv (PostgreSQL 12+), or
  • -A -t -F$'\t' (unaligned, tuples-only, explicit field separator)

plus -X to skip the startup file regardless of which output mode is chosen. rtk already injects machine-format flags with user-override detection for many other tools (go test -json, kubectl -o json, docker --format, eslint -f json, ruff/pylint --output-format, glab ci list -F json), so this would follow the existing pattern rather than introduce one.

If parsing the aligned format is deliberate — for example to preserve exactly what a user would have seen — then -X alone would still remove the ~/.psqlrc variable.

Activity

  1. added
    bug
    good first issue
    on Aug 4, 2026
  2. pszymkowiak commented on Aug 4, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 85%

    Summary

    rtk psql doesn't pass -X (or a machine-readable output mode) to psql, so a user's ~/.psqlrc can silently change table formatting and cause misparsed/shifted columns; add -X plus --csv or -A -t -F flags following rtk's existing machine-format-injection pattern.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/cmds/cloud/psql_cmd.rs

    Triaged automatically by wshm · This is an automated analysis, not a human review.

  3. nightcityblade commented on Aug 9, 2026

    @nightcityblade

    Hi, I'd like to work on this. I'll submit a PR shortly.

  4. HetCreep commented on Aug 9, 2026

    @HetCreep
    Author

    Sounds good — go for it. Happy to take a look once the PR is up.

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

    area:clibuggood first issuepriority:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions