Re: Problem with displaying "wide" tables in psql

From: Sergey Muraviov <sergey(dot)k(dot)muraviov(at)gmail(dot)com>
To: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Problem with displaying "wide" tables in psql
Date: 2013-12-11 17:43:06
Message-ID: CAJTaR33nt7HUjPodSFcoPdjEucXu0Khu02vmiYrL0MKHvUyM=g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(dot)janes(at)gmail(dot)com>

> On Mon, Dec 2, 2013 at 10:45 PM, Sergey Muraviov <
> sergey(dot)k(dot)muraviov(at)gmail(dot)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 Content-Type Size
fix_psql_print_aligned_vertical_v2.patch text/x-patch 4.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2013-12-11 17:57:28 Re: autovacuum_work_mem
Previous Message Peter Eisentraut 2013-12-11 17:42:13 Re: stats for network traffic WIP