Re: Problem with displaying "wide" tables in psql - Mailing list pgsql-hackers

From Sergey Muraviov
Subject Re: Problem with displaying "wide" tables in psql
Date
Msg-id CAJTaR33nt7HUjPodSFcoPdjEucXu0Khu02vmiYrL0MKHvUyM=g@mail.gmail.com
Whole thread Raw
In response to Re: Problem with displaying "wide" tables in psql  (Jeff Janes <jeff.janes@gmail.com>)
Responses Re: Problem with displaying "wide" tables in psql
Re: Problem with displaying "wide" tables in psql
List pgsql-hackers
Hi.

I've improved the patch.
It works in expanded mode when either format option is set to wrapped (\pset format wrapped), or we have no pager, or pager doesn't chop long lines (so you can still use the trick).
Target output width is taken from either columns option (\pset columns 70), or environment variable $COLUMNS, or terminal size.
And it's also compatible with any border style (\pset border 0|1|2).

Here are some examples:

postgres=# \x 1
postgres=# \pset format wrapped
postgres=# \pset border 0
postgres=# select * from wide_table;
* Record 1                                                                     
value afadsafasd fasdf asdfasd fsad fas df sadf sad f sadf  sadf sa df sadfsadfa
      sd fsad fsa df sadf asd fa sfd sadfsadf asdf sad f sadf sad fadsf
* Record 2                                                                     
value afadsafasd fasdf asdfasd

postgres=# \pset border 1
postgres=# \pset columns 70
postgres=# select * from wide_table;
-[ RECORD 1 ]---------------------------------------------------------
value | afadsafasd fasdf asdfasd fsad fas df sadf sad f sadf  sadf sa
      | df sadfsadfasd fsad fsa df sadf asd fa sfd sadfsadf asdf sad f
      |  sadf sad fadsf
-[ RECORD 2 ]---------------------------------------------------------
value | afadsafasd fasdf asdfasd

postgres=# \pset border 2
postgres=# \pset columns 60
postgres=# select * from wide_table;
+-[ RECORD 1 ]---------------------------------------------+
| value | afadsafasd fasdf asdfasd fsad fas df sadf sad f  |
|       | sadf  sadf sa df sadfsadfasd fsad fsa df sadf as |
|       | d fa sfd sadfsadf asdf sad f sadf sad fadsf      |
+-[ RECORD 2 ]---------------------------------------------+
| value | afadsafasd fasdf asdfasd                         |
+-------+--------------------------------------------------+

Regards,
Sergey


2013/12/10 Jeff Janes <jeff.janes@gmail.com>
On Mon, Dec 2, 2013 at 10:45 PM, Sergey Muraviov <sergey.k.muraviov@gmail.com> wrote:
Hi.

Psql definitely have a problem with displaying "wide" tables.
Even in expanded mode, they look horrible.
So I tried to solve this problem.

I get compiler warnings:

print.c: In function 'print_aligned_vertical':
print.c:1238: warning: ISO C90 forbids mixed declarations and code
print.c: In function 'print_aligned_vertical':
print.c:1238: warning: ISO C90 forbids mixed declarations and code

But I really like this and am already benefiting from it.  No point in having the string of hyphens between every record wrap to be 30 lines long just because one field somewhere down the list does so.  And configuring the pager isn't much of a solution because the pager doesn't know that the hyphens are semantically different than the other stuff getting thrown at it.

Cheers,

Jeff

 



--
Best regards,
Sergey Muraviov
Attachment

pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: stats for network traffic WIP
Next
From: Robert Haas
Date:
Subject: Re: autovacuum_work_mem