@@ -2105,12 +2105,34 @@ Tue Oct 26 21:40:57 CEST 1999
21052105
21062106
21072107 <varlistentry>
2108- <term><literal>\g [ <replaceable class="parameter">filename</replaceable> ]</literal></term>
2109- <term><literal>\g [ |<replaceable class="parameter">command</replaceable> ]</literal></term>
2108+ <term><literal>\g [ (<replaceable class="parameter">option</replaceable>=<replaceable class="parameter">value</replaceable> [...]) ] [ <replaceable class="parameter">filename</replaceable> ]</literal></term>
2109+ <term><literal>\g [ (<replaceable class="parameter">option</replaceable>=<replaceable class="parameter">value</replaceable> [...]) ] [ |<replaceable class="parameter">command</replaceable> ]</literal></term>
21102110 <listitem>
21112111 <para>
21122112 Sends the current query buffer to the server for execution.
2113- If an argument is given, the query's output is written to the named
2113+ </para>
2114+ <para>
2115+ If parentheses appear after <literal>\g</literal>, they surround a
2116+ space-separated list
2117+ of <replaceable class="parameter">option</replaceable><literal>=</literal><replaceable class="parameter">value</replaceable>
2118+ formatting-option clauses, which are interpreted in the same way
2119+ as <literal>\pset</literal>
2120+ <replaceable class="parameter">option</replaceable>
2121+ <replaceable class="parameter">value</replaceable> commands, but take
2122+ effect only for the duration of this query. In this list, spaces are
2123+ not allowed around <literal>=</literal> signs, but are required
2124+ between option clauses.
2125+ If <literal>=</literal><replaceable class="parameter">value</replaceable>
2126+ is omitted, the
2127+ named <replaceable class="parameter">option</replaceable> is changed
2128+ in the same way as for
2129+ <literal>\pset</literal> <replaceable class="parameter">option</replaceable>
2130+ with no explicit <replaceable class="parameter">value</replaceable>.
2131+ </para>
2132+ <para>
2133+ If a <replaceable class="parameter">filename</replaceable>
2134+ or <literal>|</literal><replaceable class="parameter">command</replaceable>
2135+ argument is given, the query's output is written to the named
21142136 file or piped to the given shell command, instead of displaying it as
21152137 usual. The file or command is written to only if the query
21162138 successfully returns zero or more tuples, not if the query fails or
@@ -2119,13 +2141,15 @@ Tue Oct 26 21:40:57 CEST 1999
21192141 <para>
21202142 If the current query buffer is empty, the most recently sent query is
21212143 re-executed instead. Except for that behavior, <literal>\g</literal>
2122- without an argument is essentially equivalent to a semicolon.
2123- A <literal>\g</literal> with argument is a <quote>one-shot</quote>
2124- alternative to the <command>\o</command> command.
2144+ without any arguments is essentially equivalent to a semicolon.
2145+ With arguments, <literal>\g</literal> provides
2146+ a <quote>one-shot</quote> alternative to the <command>\o</command>
2147+ command, and additionally allows one-shot adjustments of the
2148+ output formatting options normally set by <literal>\pset</literal>.
21252149 </para>
21262150 <para>
2127- If the argument begins with <literal>|</literal>, then the entire remainder
2128- of the line is taken to be
2151+ When the last argument begins with <literal>|</literal>, the entire
2152+ remainder of the line is taken to be
21292153 the <replaceable class="parameter">command</replaceable> to execute,
21302154 and neither variable interpolation nor backquote expansion are
21312155 performed in it. The rest of the line is simply passed literally to
@@ -2246,12 +2270,14 @@ hello 10
22462270
22472271
22482272 <varlistentry>
2249- <term><literal>\gx [ <replaceable class="parameter">filename</replaceable> ]</literal></term>
2250- <term><literal>\gx [ |<replaceable class="parameter">command</replaceable> ]</literal></term>
2273+ <term><literal>\gx [ (<replaceable class="parameter">option</replaceable>=<replaceable class="parameter">value</replaceable> [...]) ] [ <replaceable class="parameter">filename</replaceable> ]</literal></term>
2274+ <term><literal>\gx [ (<replaceable class="parameter">option</replaceable>=<replaceable class="parameter">value</replaceable> [...]) ] [ |<replaceable class="parameter">command</replaceable> ]</literal></term>
22512275 <listitem>
22522276 <para>
2253- <literal>\gx</literal> is equivalent to <literal>\g</literal>, but
2254- forces expanded output mode for this query. See <literal>\x</literal>.
2277+ <literal>\gx</literal> is equivalent to <literal>\g</literal>, except
2278+ that it forces expanded output mode for this query, as
2279+ if <literal>expanded=on</literal> were included in the list of
2280+ <literal>\pset</literal> options. See also <literal>\x</literal>.
22552281 </para>
22562282 </listitem>
22572283 </varlistentry>
@@ -4879,9 +4905,31 @@ second | three
48794905-[ RECORD 4 ]-
48804906first | 4
48814907second | four
4882- </programlisting></para>
4908+ </programlisting>
4909+ </para>
4910+
4911+ <para>
4912+ Also, these output format options can be set for just one query by using
4913+ <literal>\g</literal>:
4914+ <programlisting>
4915+ peter@localhost testdb=> <userinput>SELECT * FROM my_table</userinput>
4916+ peter@localhost testdb-> <userinput>\g (format=aligned tuples_only=off expanded=on)</userinput>
4917+ -[ RECORD 1 ]-
4918+ first | 1
4919+ second | one
4920+ -[ RECORD 2 ]-
4921+ first | 2
4922+ second | two
4923+ -[ RECORD 3 ]-
4924+ first | 3
4925+ second | three
4926+ -[ RECORD 4 ]-
4927+ first | 4
4928+ second | four
4929+ </programlisting>
4930+ </para>
48834931
4884- <para>
4932+ <para>
48854933 When suitable, query results can be shown in a crosstab representation
48864934 with the <command>\crosstabview</command> command:
48874935<programlisting>
0 commit comments