After long search, finally figured out!
I have a table that i want to lookup in psql client (I really don’t like heavy weight tools eg:sqldeverloper, oracle etc.) The problem is table is huge is and its folded and shown, the columns and its record values is hard to map. (eg: from pg_type)
You can enable Extended display as, \x # This option helpes to display in vertical fashion. line1:columns:values of Record1 line2:columns:values of Record2
The above also won’t help much if i have too many records.
There’s an Environment Variable available for modifying the table view.
export PAGER=”/usr/bin/less -S”
really does the magic and doesn’t fold lines and shows me the record with horizontal scroll view. Awesome! (you can add it in your ~/.bashrc or ~/.zshrc file) alternatively you can pass the variable while invoking the psql or other clients:
PAGER="less -S" psql # -S flag is important as it says less not to fold lines. man less | grep ' \-S ' -A 4 -S or --chop-long-lines Causes lines longer than the screen width to be chopped rather than folded. That is, the portion of a long line that does not fit in the screen width is not shown. The default is to fold long lines; that is, display the remainder on the next line.
A sample horizontal output from the table:
select * from pg_type;
One More cool thing i found was we can set the editor for psql and we can edit the last query, (its hard to use history and edit in pasted manner)
set PSQL_EDITOR=vi #or whatever editor you like (emacs, sublime,...)
then /e #opens the editor with last query :)
It works both with pgcli and psql. if you wonder what pgcli is, its simlary client for postgres with additional features like, auto completion of tables, selecting columns, or psql options (\?) based on the context.
DevInfo It worked In: Mac, psql (PostgreSQL) version 9.4.4, pgcli Version: 0.19.1