Add psql's \crosstabview - #1642
Open
anandghegde wants to merge 1 commit into
Open
anandghegde wants to merge 1 commit into
anandghegde wants to merge 1 commit into
Conversation
\crosstabview [colV [colH [colD [sortcolH]]]] runs the query and shows the result as a crosstab grid: the distinct values of colV down the side, of colH across the top, colD in the cells. It follows psql's crosstabview.c: columns by name (case-folded unless quoted) or number, the first three columns by default, sortcolH to order the horizontal header by an integer column (ties in name order), and psql's error messages for too few columns, ambiguous or unknown columns, and more than one value per cell. "<query> \crosstabview" is handled in PGExecute.run(), like \G, and also ends the buffer in multi-line mode. A bare \crosstabview re-runs the last query sent to the server, as in psql. Refs dbcli#1378, dbcli/pgspecial#142
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds psql's
\crosstabview [colV [colH [colD [sortcolH]]]](#1378, dbcli/pgspecial#142). It runs the query and shows the result as a grid: the values ofcolVgo down the side, the values ofcolHgo across the top, andcolDfills the cells.It follows psql's
crosstabview.c:"Quoted"names are kept as written.sortcolH, the horizontal header is sorted by that integer column: non-integers rank 0 and ties are in name order, as in psql.null_string. A cell with no data is empty.select ... \crosstabviewworks like\G:PGExecute.run()handles it, and it also ends the buffer in multi-line mode. A bare\crosstabview, orselect ...; \crosstabview, re-runs the last query sent to the server, like psql. A statement that returns no rows is shown as usual.I checked it against psql 17's
\crosstabview, using the examples from the psql docs and the error cases, on a Docker Postgres. The grid shape, the header order (includingsortcolH) and the error text match. Where pgcli prints differently, it does so by design:SELECT ninstead of(n rows),Trueinstead oft,<null>for NULL.Checklist
changelog.rst.AUTHORSfile (or it's already there).pip install pre-commit && pre-commit install).