psql expanded auto

Started by Peter Eisentrautover 15 years ago14 messageshackers
Jump to latest
#1Peter Eisentraut
peter_e@gmx.net

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.

Attachments:

psql-expanded-auto.difftext/x-patch; charset=UTF-8; name=psql-expanded-auto.diffDownload+33-17
#2Chris Browne
cbbrowne@acm.org
In reply to: Peter Eisentraut (#1)
Re: psql expanded auto

peter_e@gmx.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

#3Itagaki Takahiro
itagaki.takahiro@gmail.com
In reply to: Peter Eisentraut (#1)
Re: psql expanded auto

On Sat, Dec 18, 2010 at 07:12, Peter Eisentraut <peter_e@gmx.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

#4Bruce Momjian
bruce@momjian.us
In reply to: Peter Eisentraut (#1)
Re: psql expanded auto

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@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

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

#5Bruce Momjian
bruce@momjian.us
In reply to: Peter Eisentraut (#1)
Re: psql expanded auto

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@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

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

#6Peter Eisentraut
peter_e@gmx.net
In reply to: Peter Eisentraut (#1)
Re: psql expanded auto

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.

Attachments:

psql-expanded-auto.patchtext/x-patch; charset=UTF-8; name=psql-expanded-auto.patchDownload+66-32
#7Jan Lentfer
Jan.Lentfer@web.de
In reply to: Peter Eisentraut (#6)
Re: psql expanded auto

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.

#8Dimitri Fontaine
dimitri@2ndQuadrant.fr
In reply to: Peter Eisentraut (#6)
Re: psql expanded auto

Peter Eisentraut <peter_e@gmx.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

#9Noah Misch
noah@leadboat.com
In reply to: Peter Eisentraut (#6)
Re: psql expanded auto

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

In reply to: Peter Eisentraut (#1)
Re: psql expanded auto

On 17 December 2010 22:12, Peter Eisentraut <peter_e@gmx.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

#11Peter Eisentraut
peter_e@gmx.net
In reply to: Noah Misch (#9)
Re: psql expanded auto

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.

#12Noah Misch
noah@leadboat.com
In reply to: Peter Eisentraut (#11)
Re: psql expanded auto

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.

#13Peter Eisentraut
peter_e@gmx.net
In reply to: Noah Misch (#12)
Re: psql expanded auto

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.

Attachments:

psql-expanded-auto-v2.patchtext/x-patch; charset=UTF-8; name=psql-expanded-auto-v2.patchDownload+73-37
#14Noah Misch
noah@leadboat.com
In reply to: Peter Eisentraut (#13)
Re: psql expanded auto

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.