psql expanded auto

Lists: pgsql-hackers
From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: psql expanded auto
Date: 2010-12-17 22:12:50
Message-ID: 1292623970.22053.8.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I have often found myself wanting that psql automatically switch between
normal and \x mode depending on the width of the output. Would others
find this useful?

Attached is a crude demo patch. Enable with \pset expanded auto.

Attachment Content-Type Size
psql-expanded-auto.diff text/x-patch 4.9 KB

From: Chris Browne <cbbrowne(at)acm(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql expanded auto
Date: 2010-12-17 23:15:58
Message-ID: 874oacyor5.fsf@cbbrowne.afilias-int.info
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

peter_e(at)gmx(dot)net (Peter Eisentraut) writes:
> I have often found myself wanting that psql automatically switch between
> normal and \x mode depending on the width of the output. Would others
> find this useful?

I haven't tested the patch, but that *does* sound generally useful.
It's no fun trying to get one's eyes to visually line up output that
spans 3 lines...
--
select 'cbbrowne' || '@' || 'gmail.com';
http://linuxdatabases.info/info/nonrdbms.html
"Very little is known about the War of 1812 because the Americans lost
it." -- Eric Nicol


From: Itagaki Takahiro <itagaki(dot)takahiro(at)gmail(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql expanded auto
Date: 2010-12-18 05:08:13
Message-ID: AANLkTimo-JtczPsU_-06k+CKvHbAK4FNu=QNBDh0JkQ7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Dec 18, 2010 at 07:12, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> I have often found myself wanting that psql automatically switch between
> normal and \x mode depending on the width of the output.  Would others
> find this useful?

+1

> Attached is a crude demo patch.  Enable with \pset expanded auto.

How about adding not only "auto" but also "on" and "off" as arguments
for \x? If not specified, the default behavior will be still "toggle".

--
Itagaki Takahiro


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql expanded auto
Date: 2011-01-06 19:59:41
Message-ID: 201101061959.p06Jxfs17074@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter Eisentraut wrote:
> I have often found myself wanting that psql automatically switch between
> normal and \x mode depending on the width of the output. Would others
> find this useful?
>
> Attached is a crude demo patch. Enable with \pset expanded auto.

It is a TODO:

Add auto-expanded mode so expanded output is used if the row length is
wider than the screen width.

Consider using auto-expanded mode for backslash commands like \df+.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql expanded auto
Date: 2011-03-11 03:28:01
Message-ID: 201103110328.p2B3S1s14625@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


I have added a link to this on the TODO list:

Add "auto" expanded mode that outputs in expanded format if "wrapped"
mode can't wrap the output to the screen width

* Re: psql wrapped format default for backslash-d commands
* http://archives.postgresql.org/pgsql-hackers/2010-12/msg01638.php

---------------------------------------------------------------------------

Peter Eisentraut wrote:
> I have often found myself wanting that psql automatically switch between
> normal and \x mode depending on the width of the output. Would others
> find this useful?
>
> Attached is a crude demo patch. Enable with \pset expanded auto.
>

[ Attachment, skipping... ]

>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql expanded auto
Date: 2011-11-01 04:22:47
Message-ID: 1320121367.523.1.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I wrote:
> I have often found myself wanting that psql automatically switch between
> normal and \x mode depending on the width of the output. Would others
> find this useful?
>
> Attached is a crude demo patch. Enable with \pset expanded auto.

Here is a finalized patch for this. The first hunk of the patch is the
documentation change, so you can see there how it's supposed to work.
Let me know what you think.

Attachment Content-Type Size
psql-expanded-auto.patch text/x-patch 9.0 KB

From: Jan Lentfer <Jan(dot)Lentfer(at)web(dot)de>
To:
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql expanded auto
Date: 2011-11-01 09:21:25
Message-ID: 4EAFBA15.7040408@web.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I have not tried the patch (yet), but Informix'sl dbacess would do about
the same - and it's something I really missed.

Jan
--
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.


From: Dimitri Fontaine <dimitri(at)2ndQuadrant(dot)fr>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql expanded auto
Date: 2011-11-01 18:55:51
Message-ID: m239e7wu2w.fsf@2ndQuadrant.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> Here is a finalized patch for this. The first hunk of the patch is the
> documentation change, so you can see there how it's supposed to work.
> Let me know what you think.

+1

Regards,
--
Dimitri Fontaine
http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support


From: Noah Misch <noah(at)leadboat(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql expanded auto
Date: 2011-11-04 11:34:33
Message-ID: 20111104113433.GA10071@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Nov 01, 2011 at 06:22:47AM +0200, Peter Eisentraut wrote:
> I wrote:
> > I have often found myself wanting that psql automatically switch between
> > normal and \x mode depending on the width of the output. Would others
> > find this useful?
> >
> > Attached is a crude demo patch. Enable with \pset expanded auto.
>
> Here is a finalized patch for this. The first hunk of the patch is the
> documentation change, so you can see there how it's supposed to work.
> Let me know what you think.

+1. I'm anticipating liking this enough to put it in ".psqlrc".

Perhaps this message should change to just "Target width is 120.", since it now
applies to more than just the wrapped format:

[local] test=# \pset columns 120
Target width for "wrapped" format is 120.

Similarly, psql documentation for "\pset columns" and the COLUMNS environment
variable should note expanded auto in addition to the wrapped format.

For "\pset format wrapped", we only use $COLUMNS when the output is a tty. I'm
thinking it's best, although not terribly important, to apply the same rule to
this feature.

Thanks,
nm


From: Peter Geoghegan <peter(at)2ndquadrant(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql expanded auto
Date: 2011-11-04 12:54:02
Message-ID: CAEYLb_X8ZkMGCbW1VUOVFG=RNvNqJFeLz+W=VqYefqYAyRP4bA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 17 December 2010 22:12, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> I have often found myself wanting that psql automatically switch between
> normal and \x mode depending on the width of the output.  Would others
> find this useful?

+1

Sounds like a very good idea.

--
Peter Geoghegan       http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training and Services


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Noah Misch <noah(at)leadboat(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql expanded auto
Date: 2011-11-05 14:53:56
Message-ID: 1320504836.28373.8.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On fre, 2011-11-04 at 07:34 -0400, Noah Misch wrote:
> For "\pset format wrapped", we only use $COLUMNS when the output is a
> tty. I'm thinking it's best, although not terribly important, to
> apply the same rule to this feature.

I think it does work that way. There is only one place where the
environment variable is queries, and it's used for both wrapped format
and expanded auto format.


From: Noah Misch <noah(at)leadboat(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql expanded auto
Date: 2011-11-05 16:26:27
Message-ID: 20111105162627.GB32349@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Nov 05, 2011 at 04:53:56PM +0200, Peter Eisentraut wrote:
> On fre, 2011-11-04 at 07:34 -0400, Noah Misch wrote:
> > For "\pset format wrapped", we only use $COLUMNS when the output is a
> > tty. I'm thinking it's best, although not terribly important, to
> > apply the same rule to this feature.
>
> I think it does work that way. There is only one place where the
> environment variable is queries, and it's used for both wrapped format
> and expanded auto format.

You're correct; given output to a non-tty and no use of \pset columns,
output_columns always becomes zero. This makes wrapped format never wrap, but
it makes expanded auto mode always expand. Would it be more consistent to never
expand when output_columns == 0? That is, make these give the same output:

psql -X -P expanded=auto -c "select 'a' as a"
psql -X -P expanded=auto -c "select 'a' as a" | cat

I just noticed: the help text for \x in slashUsage() will also need an update.


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Noah Misch <noah(at)leadboat(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql expanded auto
Date: 2011-11-08 04:36:52
Message-ID: 1320727012.31945.2.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On lör, 2011-11-05 at 12:26 -0400, Noah Misch wrote:
> On Sat, Nov 05, 2011 at 04:53:56PM +0200, Peter Eisentraut wrote:
> > On fre, 2011-11-04 at 07:34 -0400, Noah Misch wrote:
> > > For "\pset format wrapped", we only use $COLUMNS when the output is a
> > > tty. I'm thinking it's best, although not terribly important, to
> > > apply the same rule to this feature.
> >
> > I think it does work that way. There is only one place where the
> > environment variable is queries, and it's used for both wrapped format
> > and expanded auto format.
>
> You're correct; given output to a non-tty and no use of \pset columns,
> output_columns always becomes zero. This makes wrapped format never wrap, but
> it makes expanded auto mode always expand. Would it be more consistent to never
> expand when output_columns == 0? That is, make these give the same output:
>
> psql -X -P expanded=auto -c "select 'a' as a"
> psql -X -P expanded=auto -c "select 'a' as a" | cat
>
> I just noticed: the help text for \x in slashUsage() will also need an update.

Here is an updated patch that addresses all the issues you pointed out.

Attachment Content-Type Size
psql-expanded-auto-v2.patch text/x-patch 10.9 KB

From: Noah Misch <noah(at)leadboat(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql expanded auto
Date: 2011-11-10 23:53:13
Message-ID: 20111110235313.GC22351@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Nov 08, 2011 at 06:36:52AM +0200, Peter Eisentraut wrote:
> Here is an updated patch that addresses all the issues you pointed out.

Looks ready to me. Thanks.