instead. Except for that behavior, <literal>\g</literal>
without any arguments is essentially equivalent to a semicolon.
With arguments, <literal>\g</literal> provides
a <quote>one-shot</quote> alternative to the <command>\o</command>
command, and additionally allows one-shot adjustments of the
output formatting options normally set by <literal>\pset</literal>.
</para>
<para>
When the last argument begins with <literal>|</literal>, the entire
remainder of the line is taken to be
the <replaceable class="parameter">command</replaceable> to execute,
and neither variable interpolation nor backquote expansion are
performed in it. The rest of the line is simply passed literally to
the shell.
</para>
</listitem>
</varlistentry>
<varlistentry id="app-psql-meta-command-gdesc">
<term><literal>\gdesc</literal></term>
<listitem>
<para>
Shows the description (that is, the column names and data types)
of the result of the current query buffer. The query is not
actually executed; however, if it contains some type of syntax
error, that error will be reported in the normal way.
</para>
<para>
If the current query buffer is empty, the most recently sent query
is described instead.
</para>
</listitem>
</varlistentry>
<varlistentry id="app-psql-meta-command-getenv">
<term><literal>\getenv <replaceable class="parameter">psql_var</replaceable> <replaceable class="parameter">env_var</replaceable></literal></term>
<listitem>
<para>
Gets the value of the environment
variable <replaceable class="parameter">env_var</replaceable>
and assigns it to the <application>psql</application>
variable <replaceable class="parameter">psql_var</replaceable>.
If <replaceable class="parameter">env_var</replaceable> is
not defined in the <application>psql</application> process's
environment, <replaceable class="parameter">psql_var</replaceable>
is not changed. Example:
<programlisting>
=> <userinput>\getenv home HOME</userinput>
=> <userinput>\echo :home</userinput>
/home/postgres
</programlisting></para>
</listitem>
</varlistentry>
<varlistentry id="app-psql-meta-command-gexec">
<term><literal>\gexec</literal></term>
<listitem>
<para>
Sends the current query buffer to the server, then treats
each column of each row of the query's output (if any) as an SQL
statement to be executed. For example, to create an index on each
column of <structname>my_table</structname>:
<programlisting>
=> <userinput>SELECT format('create index on my_table(%I)', attname)</userinput>
-> <userinput>FROM pg_attribute</userinput>
-> <userinput>WHERE attrelid = 'my_table'::regclass AND attnum > 0</userinput>
-> <userinput>ORDER BY attnum</userinput>
-> <userinput>\gexec</userinput>
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
</programlisting>
</para>
<para>
The generated queries are executed in the order in which the rows
are returned, and left-to-right within each row if there is more
than one column. NULL fields are ignored. The generated queries
are sent literally to the server for processing, so they cannot be
<application>psql</application> meta-commands nor contain <application>psql</application>
variable references. If any individual query fails, execution of
the remaining queries continues
unless <varname>ON_ERROR_STOP</varname> is set. Execution of each
query is subject to <varname>ECHO</varname> processing.
(Setting <varname>ECHO</varname> to <literal>all</literal>
or <literal>queries</literal> is often