*** ./doc/src/sgml/ref/psql-ref.sgml.orig	2008-04-03 00:53:15.697658287 +0200
--- ./doc/src/sgml/ref/psql-ref.sgml	2008-04-03 00:42:16.484091846 +0200
***************
*** 1267,1272 ****
--- 1267,1286 ----
        </varlistentry>
  
        <varlistentry>
+         <term><literal>\G</literal> [ { <replaceable class="parameter">filename</replaceable> | <literal>|</literal><replaceable class="parameter">command</replaceable> } ]</term>
+ 
+         <listitem>
+         <para>
+         Sends the current query input buffer to the server in
+ 		expanded table output.  Apart from that it is virtually
+ 		equivalent to <literal>\g</literal>.  A <literal>\G</literal>
+ 		is <quote>one-shot</quote> alternative to the
+ 		<command>\x</command> command.
+         </para>
+         </listitem>
+       </varlistentry>
+ 
+       <varlistentry>
          <term><literal>\help</literal> (or <literal>\h</literal>) <literal>[ <replaceable class="parameter">command</replaceable> ]</literal></term>
          <listitem>
          <para>
*** ./src/bin/psql/command.c.orig	2008-04-03 00:49:08.407566027 +0200
--- ./src/bin/psql/command.c	2008-04-03 09:00:34.780234997 +0200
***************
*** 532,539 ****
  		free(fname);
  	}
  
! 	/* \g means send query */
! 	else if (strcmp(cmd, "g") == 0)
  	{
  		char	   *fname = psql_scan_slash_option(scan_state,
  												   OT_FILEPIPE, NULL, false);
--- 532,542 ----
  		free(fname);
  	}
  
! 	/* 
! 	 * \g means send query, while
! 	 * \G means send query and output in expanded mode
! 	 */
! 	else if (strcmp(cmd, "g") == 0 || strcmp(cmd, "G") == 0)
  	{
  		char	   *fname = psql_scan_slash_option(scan_state,
  												   OT_FILEPIPE, NULL, false);
***************
*** 547,552 ****
--- 550,562 ----
  		}
  		free(fname);
  		status = PSQL_CMD_SEND;
+ 
+ 		/* \G -- turn expanded mode, but only for one query */
+ 		if (cmd[0]=='G' && !pset.popt.topt.expanded)
+ 		{
+ 			pset.popt.topt.expanded = true;
+ 			pset.popt.topt.expand_once = true;
+ 		}
  	}
  
  	/* help */
*** ./src/bin/psql/common.c.orig	2008-04-03 00:49:08.411566255 +0200
--- ./src/bin/psql/common.c	2008-04-03 00:31:34.727520223 +0200
***************
*** 602,607 ****
--- 602,614 ----
  	else
  		printQuery(results, &my_popt, pset.queryFout, pset.logfile);
  
+ 	/* If running expand once (\G) command, turn expand off afterwards */
+ 	if (pset.popt.topt.expand_once)
+ 	{
+ 		pset.popt.topt.expand_once = false;
+ 		pset.popt.topt.expanded = false;
+ 	}
+ 
  	return true;
  }
  
*** ./src/bin/psql/help.c.orig	2008-04-03 00:49:08.415566483 +0200
--- ./src/bin/psql/help.c	2008-04-03 00:51:56.705156760 +0200
***************
*** 193,198 ****
--- 193,199 ----
  	fprintf(output, _("Query Buffer\n"));
  	fprintf(output, _("  \\e [FILE]      edit the query buffer (or file) with external editor\n"));
  	fprintf(output, _("  \\g [FILE]      send query buffer to server (and results to file or |pipe)\n"));
+ 	fprintf(output, _("  \\G [FILE]      send query buffer to server and output in expanded format\n"));
  	fprintf(output, _("  \\p             show the contents of the query buffer\n"));
  	fprintf(output, _("  \\r             reset (clear) the query buffer\n"));
  #ifdef USE_READLINE
*** ./src/bin/psql/print.h.orig	2008-04-03 00:49:08.419566711 +0200
--- ./src/bin/psql/print.h	2008-04-03 00:09:15.273876665 +0200
***************
*** 33,38 ****
--- 33,39 ----
  	enum printFormat format;	/* one of the above */
  	bool		expanded;		/* expanded/vertical output (if supported by
  								 * output format) */
+ 	bool		expand_once;	/* Use expanded format for one query only */
  	unsigned short int border;	/* Print a border around the table. 0=none,
  								 * 1=dividing lines, 2=full */
  	unsigned short int pager;	/* use pager for output (if to stdout and
*** ./src/bin/psql/tab-complete.c.orig	2008-04-03 00:49:08.423566939 +0200
--- ./src/bin/psql/tab-complete.c	2008-04-03 00:34:19.376903057 +0200
***************
*** 624,630 ****
  		"\\dF", "\\dFd", "\\dFp", "\\dFt", "\\dg", "\\di", "\\dl",
  		"\\dn", "\\do", "\\dp", "\\ds", "\\dS", "\\dt", "\\dT", "\\dv", "\\du",
  		"\\e", "\\echo", "\\encoding",
! 		"\\f", "\\g", "\\h", "\\help", "\\H", "\\i", "\\l",
  		"\\lo_import", "\\lo_export", "\\lo_list", "\\lo_unlink",
  		"\\o", "\\p", "\\password", "\\prompt", "\\pset", "\\q", "\\qecho", "\\r",
  		"\\set", "\\t", "\\T",
--- 624,630 ----
  		"\\dF", "\\dFd", "\\dFp", "\\dFt", "\\dg", "\\di", "\\dl",
  		"\\dn", "\\do", "\\dp", "\\ds", "\\dS", "\\dt", "\\dT", "\\dv", "\\du",
  		"\\e", "\\echo", "\\encoding",
! 		"\\f", "\\g", "\\G", "\\h", "\\help", "\\H", "\\i", "\\l",
  		"\\lo_import", "\\lo_export", "\\lo_list", "\\lo_unlink",
  		"\\o", "\\p", "\\password", "\\prompt", "\\pset", "\\q", "\\qecho", "\\r",
  		"\\set", "\\t", "\\T",
***************
*** 2119,2125 ****
  	}
  	else if (strcmp(prev_wd, "\\cd") == 0 ||
  			 strcmp(prev_wd, "\\e") == 0 || strcmp(prev_wd, "\\edit") == 0 ||
! 			 strcmp(prev_wd, "\\g") == 0 ||
  		  strcmp(prev_wd, "\\i") == 0 || strcmp(prev_wd, "\\include") == 0 ||
  			 strcmp(prev_wd, "\\o") == 0 || strcmp(prev_wd, "\\out") == 0 ||
  			 strcmp(prev_wd, "\\s") == 0 ||
--- 2119,2125 ----
  	}
  	else if (strcmp(prev_wd, "\\cd") == 0 ||
  			 strcmp(prev_wd, "\\e") == 0 || strcmp(prev_wd, "\\edit") == 0 ||
! 			 strcmp(prev_wd, "\\g") == 0 || strcmp(prev_wd, "\\G") == 0 ||
  		  strcmp(prev_wd, "\\i") == 0 || strcmp(prev_wd, "\\include") == 0 ||
  			 strcmp(prev_wd, "\\o") == 0 || strcmp(prev_wd, "\\out") == 0 ||
  			 strcmp(prev_wd, "\\s") == 0 ||
