`rtk psql` parses psql's aligned table output without `-X`, so a user's `~/.psqlrc` silently changes what rtk reads
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 81.1k
- Forks
- 5.1k
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 40
Description
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.:111and:19/:63implement the parse:is_table_formatlooks for the|separator and the[-+]+rule line, and the summary keys off(N rows).
What breaks it
~/.psqlrcis honoured.\pset border 0or\pset border 2,\pset format wrapped|csv|html,\pset fieldsep, or\pset linestyle unicodeall change the output shape.linestyle unicodeemits│and─instead of|and-, sois_table_formatstops recognising the output as a table at all.(N rows)is translated. It goes through NLS, so on a server or client with a non-Englishlc_messagesthe footer text differs and the row-count summary misses.- 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/cmds/cloud/psql_cmd.rs, especially run at lines 29-45 and the parsing logic around lines 19, 63, and 111. Review how the command is built and how table separators and the (N rows) footer are parsed, then reproduce the listed ~/.psqlrc, locale, and pipe-in-cell cases with psql when available. Done means the chosen supported behavior is stable and does not silently misparse affected output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, rust
- Domain
- cli, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100