Take the 2-minute tour ×
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. It's 100% free, no registration required.

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

From:

SELECT * FROM test;
test_id |                                  text
--------+-----------------------------------------------------------------------
      1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris lorem

To:

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? –  Coder Hawk 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
add comment

1 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
add comment

Your Answer

 
discard

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.