Skip to content

sql: readable human output — table by default, plus --vertical and \G support - #1342

Open
mcrauwel wants to merge 2 commits into
mainfrom
mcrauwel/sql-vertical-output
Open

sql: readable human output — table by default, plus --vertical and \G support#1342
mcrauwel wants to merge 2 commits into
mainfrom
mcrauwel/sql-vertical-output

Conversation

@mcrauwel

Copy link
Copy Markdown
Member

What

pscale sql human output printed each row with Go's %v map formatting — unordered keys, map[...] syntax — which is unreadable for wide results such as SHOW REPLICA STATUS. And a trailing \G, which mysql users reach for out of habit, was sent to the server verbatim and rejected with Error 1105: syntax error.

This PR makes the human format render results the way the mysql client does:

  • Table by default: rows render as an aligned ASCII table, columns in the order the server returned them, NULL shown as NULL.
  • --vertical flag: one column per line with right-aligned names (*************************** 1. row *************************** style), for wide rows.
  • Trailing \G / \g: stripped client-side before the query is sent (they are mysql client terminators, not SQL). \G also enables vertical output, matching mysql semantics; \g is just stripped.

JSON and CSV output formats are unchanged.

Before

❯ pscale sql mydb main --org myorg --query "show replica status\G" --replica
Error: Error 1105 (HY000): syntax error at position 21 near 'status'
❯ pscale sql mydb main --org myorg --query "show replica status" --replica
Returned 1 row(s)
1: map[Auto_Position:1 Channel_Name: Connect_Retry:10 Exec_Source_Log_Pos:505711876 ...]

After

❯ pscale sql mydb main --org myorg --query "show replica status\G" --replica
*************************** 1. row ***************************
             Replica_IO_State: Waiting for source to send event
                  Source_Host: 10.x.x.x
                  Source_User: vt_repl
                  ...
Returned 1 row(s)

Tests

  • stripVerticalTerminator: trailing \G/\g with/without whitespace, mid-string \G untouched, bare terminator
  • renderTable: golden-string check for column order, alignment, borders, NULL; multi-line values (GTID sets) sized to their longest line without breaking the table
  • renderVertical: golden-string check for right-aligned names and row headers
  • printHumanResult: rows-affected, zero-rows, table, and vertical branches; asserts no map[ in output
  • --vertical flag registration

🤖 Generated with Claude Code

pscale sql printed each row with Go's %v map formatting, which is unordered
and unreadable for wide results (e.g. SHOW REPLICA STATUS). A trailing \G,
which mysql users reach for out of habit, was passed to the server verbatim
and rejected with a syntax error.

- Render human output as a mysql-style table, columns in server order
- Add --vertical to print one column per line (mysql \G style)
- Strip a trailing \G / \g client terminator before sending the query;
  \G also enables vertical output, matching the mysql client
- Render NULL as NULL instead of <nil>

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mcrauwel
mcrauwel marked this pull request as ready for review August 17, 2026 12:14
@mcrauwel
mcrauwel requested a review from a team as a code owner August 17, 2026 12:14

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit cb79b21. Configure here.

Comment thread internal/cmd/sql/render.go
A cell with embedded newlines (e.g. a GTID set) was printed verbatim
mid-row, pushing later columns onto a borderless continuation line.
Spread the logical row over multiple physical lines instead, padding
every column on every line.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant