'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 advisable when
using <command>\gexec</command>.) Query logging, single-step mode,
timing, and other query execution features apply to each generated
query as well.
</para>
<para>
If the current query buffer is empty, the most recently sent query
is re-executed instead.
</para>
</listitem>
</varlistentry>
<varlistentry id="app-psql-meta-command-gset">
<term><literal>\gset [ <replaceable class="parameter">prefix</replaceable> ]</literal></term>
<listitem>
<para>
Sends the current query buffer to the server and stores the
query's output into <application>psql</application> variables
(see <xref linkend="app-psql-variables"/> below).
The query to be executed must return exactly one row. Each column of
the row is stored into a separate variable, named the same as the
column. For example:
<programlisting>
=> <userinput>SELECT 'hello' AS var1, 10 AS var2</userinput>
-> <userinput>\gset</userinput>
=> <userinput>\echo :var1 :var2</userinput>
hello 10
</programlisting>
</para>
<para>
If you specify a <replaceable class="parameter">prefix</replaceable>,
that string is prepended to the query's column names to create the
variable names to use:
<programlisting>
=> <userinput>SELECT 'hello' AS var1, 10 AS var2</userinput>
-> <userinput>\gset result_</userinput>
=> <userinput>\echo :result_var1 :result_var2</userinput>
hello 10
</programlisting>
</para>
<para>
If a column result is NULL, the corresponding variable is unset
rather than being set.
</para>
<para>
If the query fails or does not return one row,
no variables are changed.
</para>
<para>
If the current query buffer is empty, the most recently sent query
is re-executed instead.
</para>
</listitem>
</varlistentry>
<varlistentry id="app-psql-meta-command-gx">
<term><literal>\gx [ (<replaceable class="parameter">option</replaceable>=<replaceable class="parameter">value</replaceable> [...]) ] [ <replaceable class="parameter">filename</replaceable> ]</literal></term>
<term><literal>\gx [ (<replaceable class="parameter">option</replaceable>=<replaceable class="parameter">value</replaceable> [...]) ] [ |<replaceable class="parameter">command</replaceable> ]</literal></term>
<listitem>
<para>
<literal>\gx</literal> is equivalent to <literal>\g</literal>, except
that it forces expanded output mode for this query, as
if <literal>expanded=on</literal> were included in the list of
<literal>\pset</literal> options. See also <literal>\x</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry id="app-psql-meta-command-help">
<term><literal>\h</literal>