Home Explore Blog CI



postgresql

13th chunk of `doc/src/sgml/ref/psql-ref.sgml`
c2a73cfc00efd7f7a99f9225cd5ee889b8b3508e5dcb47400000000100000fa3
 cause the results to be displayed in expanded
    mode, as if <command>\x</command> or <command>\pset expanded</command>
    had been used.
    </para>

    <para>
    The following meta-commands are defined:

    <variablelist>
      <varlistentry id="app-psql-meta-command-a">
        <term><literal>\a</literal></term>
        <listitem>
        <para>
        If the current table output format is unaligned, it is switched to aligned.
        If it is not unaligned, it is set to unaligned. This command is
        kept for backwards compatibility. See <command>\pset</command> for a
        more general solution.
        </para>
        </listitem>
      </varlistentry>

      <varlistentry id="app-psql-meta-command-bind">
       <term><literal>\bind</literal> [ <replaceable class="parameter">parameter</replaceable> ] ... </term>

       <listitem>
        <para>
         Sets query parameters for the next query execution, with the
         specified parameters passed for any parameter placeholders
         (<literal>$1</literal> etc.).
        </para>

        <para>
         Example:
<programlisting>
INSERT INTO tbl1 VALUES ($1, $2) \bind 'first value' 'second value' \g
</programlisting>
        </para>

        <para>
         This also works for query-execution commands besides
         <literal>\g</literal>, such as <literal>\gx</literal> and
         <literal>\gset</literal>.
        </para>

        <para>
         This command causes the extended query protocol (see <xref
         linkend="protocol-query-concepts"/>) to be used, unlike normal
         <application>psql</application> operation, which uses the simple
         query protocol.  So this command can be useful to test the extended
         query protocol from <application>psql</application>.  (The extended
         query protocol is used even if the query has no parameters and this
         command specifies zero parameters.)  This command affects only the
         next query executed; all subsequent queries will use the simple query
         protocol by default.
        </para>
       </listitem>
      </varlistentry>

      <varlistentry id="app-psql-meta-command-bind-named">
       <term><literal>\bind_named</literal> <replaceable class="parameter">statement_name</replaceable> [ <replaceable class="parameter">parameter</replaceable> ] ... </term>

       <listitem>
        <para>
         <literal>\bind_named</literal> is equivalent to <literal>\bind</literal>,
         except that it takes the name of an existing prepared statement as
         first parameter. An empty string denotes the unnamed prepared
         statement.
        </para>

        <para>
         Example:
<programlisting>
INSERT INTO tbls1 VALUES ($1, $2) \parse stmt1
\bind_named stmt1 'first value' 'second value' \g
</programlisting>
        </para>

        <para>
         This command causes the extended query protocol (see
         <xref linkend="protocol-query-concepts"/>) to be used, unlike normal
         <application>psql</application> operation, which uses the simple
         query protocol. So this command can be useful to test the extended
         query protocol from <application>psql</application>.
        </para>

       </listitem>
      </varlistentry>

      <varlistentry id="app-psql-meta-command-c-lc">
        <term><literal>\c</literal> or <literal>\connect [ -reuse-previous=<replaceable class="parameter">on|off</replaceable> ] [ <replaceable class="parameter">dbname</replaceable> [ <replaceable class="parameter">username</replaceable> ] [ <replaceable class="parameter">host</replaceable> ] [ <replaceable class="parameter">port</replaceable> ] | <replaceable class="parameter">conninfo</replaceable> ]</literal></term>
        <listitem>
        <para>
        Establishes a new connection to a <productname>PostgreSQL</productname>
        server.  The connection parameters to use can be specified either
        using a positional syntax (one or more of database name, user,

Title: psql Meta-Commands: \a, \bind, \bind_named, and \connect
Summary
This section details four psql meta-commands: \a switches between aligned and unaligned table output formats, \bind sets query parameters for the next query execution using the extended query protocol, \bind_named is similar to \bind but takes the name of an existing prepared statement, and \connect establishes a new connection to a PostgreSQL server with various connection parameters.