Prettify records with long columns in PostgreSQL shell
The chances are, once in a while, your psql
terminal session ends up looking like this:
Fixing the line wrapping is very straight-forward, just issue the following commands (or put them into ~/.psqlrc
):
\setenv PAGER less
\setenv LESS -IS
\pset linestyle unicode
The last line is optional, but draws a lot nicer tables. Now, the same query results as above will appear almost bearable:
This still sucks if the only thing want is to copy one record to your editor or IM window. It would be easier to have one-line-per-column. MySQL shell has \G
for that. psql
has \x\g\x
, so instead of:
select * from brasil_ibge where uf = 'SP' limit 10;
Just use:
select * from brasil_ibge where uf = 'SP' limit 10 \x\g\x
And there you are!
Written by Stanislaw Pusep
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#