Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm selecting from a table with long text columns. I'd like to wrap long lines to a maximum line length.


test_id |                                  text
      1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris lorem


test_id |              text
      1 | Lorem ipsum dolor sit amet,+
        | consectetur adipiscing elit+
        | . Mauris lorem
share|improve this question
On word boundaries? I don't think that feature is supported. – Gaius Mar 14 '11 at 9:40
@Gaius: Ignoring the word boundaries is ok – jkj Mar 14 '11 at 10:04
Assume you just want to see the result wrapped? Are you executing the query via commandline tool or pgAdmin or phpPgAdmin? – CoderHawk Mar 14 '11 at 11:10
@Sandy: psql command line tool – jkj Mar 14 '11 at 14:46
adjust the size of your terminal window? :D – Derek Downey Mar 17 '11 at 12:36
up vote 8 down vote accepted

If you're using the psql command line tool, issue this command first:

\pset format wrapped

It should then wrap long lines to your terminal window like so:

test_id |              text
      1 | Lorem ipsum dolor sit amet,.
        |.consectetur adipiscing elit.
        |.. Mauris lorem

You can also set the number of columns to wrap to with

\pset columns 100

and you can change the dots to ellipses with

\pset linestyle unicode

More info:

share|improve this answer

My answer won't directly answer your question because I don't think psql itself can specifically do this. But, \x will turn on expanded output, which will place your values like this:

-[ RECORD 1 ]------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
id         | 1
longstring | This is a long string of text that will be quite long and most likely be very annoying to read if you are viewing results with more than at most a few columns of data. Words words words words words words lorem ipsum.

You can also configure your pager to not wrap lines.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.