Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable wrapping in Psql output

When using Psql in Linux, if the result of my SQL query contains many columns or long strings of data, it will wrap the initial view and only once I scroll to the side will it stop wrapping and show each row on a separate line.

I've tried various \pset options such as format unaligned, format aligned, format wrapped, columns 0, columns 1000, but none seemed to fully stop wrapping unless I generate static output to a file.

How can I set it to never wrap the output while still being scrollable and showing the result using the default ascii table format?

like image 520
Silveri Avatar asked Oct 04 '16 11:10

Silveri


2 Answers

Psql uses a system viewer to show its output in the console. In bash it likely uses less for the scrollable/page-able features it provides. To use a different viewer or use different settings, you just need to set the PAGER environment variable.

Running psql to use less with the -S or --chop-long-lines option seemed to work for me:

PAGER="less -S" psql 

You can also enable this feature while viewing output in less by typing -S and Enter.

like image 195
Silveri Avatar answered Nov 07 '22 17:11

Silveri


To disable the wrapped output of the select query.

\pset pager on and \pset pager off to switch back to the older output view.

like image 37
Akshay Shet Avatar answered Nov 07 '22 15:11

Akshay Shet