Re: [HACKERS] psql expanded auto

2011-11-10 Thread Noah Misch
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.

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


Re: [HACKERS] psql expanded auto

2011-11-07 Thread Peter Eisentraut
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.

diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index d6941e0..01f57c4 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -1860,7 +1860,8 @@ lo_import 152801
   para
   Sets the target width for the literalwrapped/ format, and also
   the width limit for determining whether output is wide enough to
-  require the pager.
+  require the pager or switch to the vertical display in expanded auto
+  mode.
   Zero (the default) causes the target width to be controlled by the
   environment variable envarCOLUMNS/, or the detected screen width
   if envarCOLUMNS/ is not set.
@@ -1876,15 +1877,19 @@ lo_import 152801
   termliteralexpanded/literal (or literalx/literal)/term
   listitem
   para
-  If replaceable class=parametervalue/replaceable is specified
-  it must be either literalon/literal or literaloff/literal
-  which will enable or disable expanded mode.  If replaceable
-  class=parametervalue/replaceable is omitted the command toggles
-  between regular and expanded mode.
-  When expanded mode is enabled, query results
-  are displayed in two columns, with the column name on the left and
-  the data on the right. This mode is useful if the data wouldn't fit
-  on the screen in the normal quotehorizontal/quote mode.
+  If replaceable class=parametervalue/replaceable is specified it
+  must be either literalon/literal or literaloff/literal, which
+  will enable or disable expanded mode, or literalauto/literal.
+  If replaceable class=parametervalue/replaceable is omitted the
+  command toggles between the on and off settings.  When expanded mode
+  is enabled, query results are displayed in two columns, with the
+  column name on the left and the data on the right. This mode is
+  useful if the data wouldn't fit on the screen in the
+  normal quotehorizontal/quote mode.  In the auto setting, the
+  expanded mode is used whenever the query output is wider than the
+  screen, otherwise the regular mode is used.  The auto setting is only
+  effective in the aligned and wrapped formats.  In other formats, it
+  always behaves as if the expanded mode is off.
   /para
   /listitem
   /varlistentry
@@ -2326,10 +2331,10 @@ lo_import 152801
 
 
   varlistentry
-termliteral\x/literal/term
+termliteral\x [ replaceable class=parameteron/replaceable | replaceable class=parameteroff/replaceable | replaceable class=parameterauto/replaceable ]/literal/term
 listitem
 para
-Toggles expanded table formatting mode. As such it is equivalent to
+Sets or toggles expanded table formatting mode. As such it is equivalent to
 literal\pset expanded/literal.
/para
/listitem
@@ -3197,7 +3202,8 @@ $endif
  para
   If literal\pset columns/ is zero, controls the
   width for the literalwrapped/ format and width for determining
-  if wide output requires the pager.
+  if wide output requires the pager or should be switched to the
+  vertical format in expanded auto mode.
  /para
 /listitem
/varlistentry
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 2c38902..daaed66 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -1343,7 +1343,7 @@ exec_command(const char *cmd,
 		free(fname);
 	}
 
-	/* \x -- toggle expanded table representation */
+	/* \x -- set or toggle expanded table representation */
 	else if (strcmp(cmd, x) == 0)
 	{
 		char	   *opt = psql_scan_slash_option(scan_state,
@@ -2177,14 +2177,21 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, 

Re: [HACKERS] psql expanded auto

2011-11-05 Thread Peter Eisentraut
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.


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


Re: [HACKERS] psql expanded auto

2011-11-05 Thread Noah Misch
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.

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


Re: [HACKERS] psql expanded auto

2011-11-04 Thread Noah Misch
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

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


Re: [HACKERS] psql expanded auto

2011-11-04 Thread Peter Geoghegan
On 17 December 2010 22:12, Peter Eisentraut pete...@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

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


Re: [HACKERS] psql expanded auto

2011-11-01 Thread Jan Lentfer
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.


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


Re: [HACKERS] psql expanded auto

2011-11-01 Thread Dimitri Fontaine
Peter Eisentraut pete...@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

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


Re: [HACKERS] psql expanded auto

2011-10-31 Thread Peter Eisentraut
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.

diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index d6941e0..e0f5ef4 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -1876,15 +1876,19 @@ lo_import 152801
   termliteralexpanded/literal (or literalx/literal)/term
   listitem
   para
-  If replaceable class=parametervalue/replaceable is specified
-  it must be either literalon/literal or literaloff/literal
-  which will enable or disable expanded mode.  If replaceable
-  class=parametervalue/replaceable is omitted the command toggles
-  between regular and expanded mode.
-  When expanded mode is enabled, query results
-  are displayed in two columns, with the column name on the left and
-  the data on the right. This mode is useful if the data wouldn't fit
-  on the screen in the normal quotehorizontal/quote mode.
+  If replaceable class=parametervalue/replaceable is specified it
+  must be either literalon/literal or literaloff/literal, which
+  will enable or disable expanded mode, or literalauto/literal.
+  If replaceable class=parametervalue/replaceable is omitted the
+  command toggles between the on and off settings.  When expanded mode
+  is enabled, query results are displayed in two columns, with the
+  column name on the left and the data on the right. This mode is
+  useful if the data wouldn't fit on the screen in the
+  normal quotehorizontal/quote mode.  In the auto setting, the
+  expanded mode is used whenever the query output is wider than the
+  screen, otherwise the regular mode is used.  The auto setting is only
+  effective in the aligned and wrapped formats.  In other formats, it
+  always behaves as if the expanded mode is off.
   /para
   /listitem
   /varlistentry
@@ -2326,10 +2330,10 @@ lo_import 152801
 
 
   varlistentry
-termliteral\x/literal/term
+termliteral\x [ replaceable class=parameteron/replaceable | replaceable class=parameteroff/replaceable | replaceable class=parameterauto/replaceable ]/literal/term
 listitem
 para
-Toggles expanded table formatting mode. As such it is equivalent to
+Sets or toggles expanded table formatting mode. As such it is equivalent to
 literal\pset expanded/literal.
/para
/listitem
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 2c38902..5edeeb1 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -1343,7 +1343,7 @@ exec_command(const char *cmd,
 		free(fname);
 	}
 
-	/* \x -- toggle expanded table representation */
+	/* \x -- set or toggle expanded table representation */
 	else if (strcmp(cmd, x) == 0)
 	{
 		char	   *opt = psql_scan_slash_option(scan_state,
@@ -2177,14 +2177,21 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
 	/* set expanded/vertical mode */
 	else if (strcmp(param, x) == 0 || strcmp(param, expanded) == 0 || strcmp(param, vertical) == 0)
 	{
-		if (value)
+		if (value  pg_strcasecmp(value, auto) == 0)
+			popt-topt.expanded = 2;
+		else if (value)
 			popt-topt.expanded = ParseVariableBool(value);
 		else
 			popt-topt.expanded = !popt-topt.expanded;
 		if (!quiet)
-			printf(popt-topt.expanded
-   ? _(Expanded display is on.\n)
-   : _(Expanded display is off.\n));
+		{
+			if (popt-topt.expanded == 1)
+printf(_(Expanded display is on.\n));
+			else if (popt-topt.expanded == 2)
+printf(_(Expanded display is used automatically.\n));
+			else
+printf(_(Expanded display is off.\n));
+		}
 	}
 
 	/* locale-aware numeric output */
diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c
index 0d18665..c693040 100644
--- a/src/bin/psql/print.c
+++ b/src/bin/psql/print.c
@@ -122,9 +122,11 @@ const printTextFormat pg_utf8format =
 
 /* Local functions */
 static int	strlen_max_width(unsigned char *str, int *target_width, int encoding);
-static void IsPagerNeeded(const printTableContent *cont, const int extra_lines,
+static void IsPagerNeeded(const printTableContent *cont, const int extra_lines, bool expanded,
 			  FILE **fout, bool *is_pager);
 
+static void print_aligned_vertical(const printTableContent *cont, FILE *fout);
+
 
 static void *
 pg_local_malloc(size_t size)
@@ -713,6 +715,17 @@ print_aligned_text(const printTableContent *cont, FILE *fout)
 		}
 	}
 
+	/*
+	 * If in expanded auto mode, we have now calculated the 

Re: [HACKERS] psql expanded auto

2011-03-10 Thread Bruce Momjian

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

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

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


Re: [HACKERS] psql expanded auto

2011-01-06 Thread Bruce Momjian
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  br...@momjian.ushttp://momjian.us
  EnterpriseDB http://enterprisedb.com

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

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


Re: [HACKERS] psql expanded auto

2010-12-17 Thread Chris Browne
pete...@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

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


Re: [HACKERS] psql expanded auto

2010-12-17 Thread Itagaki Takahiro
On Sat, Dec 18, 2010 at 07:12, Peter Eisentraut pete...@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

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