very long record lines in expanded psql output - Mailing list pgsql-hackers

From Platon Pronko
Subject very long record lines in expanded psql output
Date
Msg-id f03d38a3-db96-a56e-d1bc-dbbc80bbde4d@gmail.com
Whole thread Raw
Responses Re: very long record lines in expanded psql output  (Pavel Stehule <pavel.stehule@gmail.com>)
Re: very long record lines in expanded psql output  ("Daniel Verite" <daniel@manitou-mail.org>)
List pgsql-hackers
In expanded mode psql calculates the width of the longest field in all the output rows,
and prints the header line according to it. This often results in record header wrapping
over several lines (see example below).

This huge record header is printed the same way before each record, even if all the fields
in current record are small and fit into terminal width. This often leads to situations
when record header occupies the entirety of the screen, for all records, even though there are
only a few records with huge fields in a record set.

Maybe we can avoid making the header line longer than terminal width for \pset border 0
and \pset border 1? We already have terminal width calculated. Please see attached a patch
with the proposed implementation.

Example output before the modification, in a terminal with a 100-column width:

$ psql template1 -c "\x on" -c "\pset border 1;" -c "select n, repeat('x', n) as long_column_name from
unnest(array[42,210])as n"
 
Expanded display is on.
Border style is 1.
─[ RECORD 1 ]────┬──────────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────────────────────────────
─────────────────────────────
n                │ 42
long_column_name │ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
─[ RECORD 2 ]────┼──────────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────────────────────────────
─────────────────────────────
n                │ 210
long_column_name │ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

And here's the same command after the patch:

$ psql template1 -c "\x on" -c "\pset border 1;" -c "select n, repeat('x', n) as long_column_name from
unnest(array[42,210])as n"
 
Expanded display is on.
Border style is 1.
─[ RECORD 1 ]────┬──────────────────────────────────────────────────────────────────────────────────
n                │ 42
long_column_name │ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
─[ RECORD 2 ]────┼──────────────────────────────────────────────────────────────────────────────────
n                │ 210
long_column_name │ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Best regards,
Platon Pronko

Attachment

pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: Added schema level support for publication.
Next
From: Pavel Stehule
Date:
Subject: Re: very long record lines in expanded psql output