rtk-ai / rtk-ai/rtk

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

Open
#3,395 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:cli bug good first issue priority:high
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.
  • :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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.