Home Explore Blog CI



postgresql

16th chunk of `doc/src/sgml/ref/psql-ref.sgml`
ddb619e17679ce3d5b938fd0126d2a97ec0a6fd151979e1c0000000100000fa0
 id="app-psql-meta-command-close">
       <term><literal>\close</literal> <replaceable class="parameter">prepared_statement_name</replaceable></term>

       <listitem>
        <para>
         Closes the specified prepared statement. An empty string denotes the
         unnamed prepared statement. If no prepared statement exists with this
         name, the operation is a no-op.
        </para>

        <para>
         Example:
<programlisting>
SELECT $1 \parse stmt1
\close stmt1
</programlisting>
        </para>

        <para>
         This command causes the extended query protocol 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-conninfo">
        <term><literal>\conninfo</literal></term>
        <listitem>
         <para>
          Outputs information about the current database connection,
          including TLS-related information if TLS is in use.
         </para>
        </listitem>
      </varlistentry>

      <varlistentry id="app-psql-meta-commands-copy">
        <term><literal>\copy { <replaceable class="parameter">table</replaceable> [ ( <replaceable class="parameter">column_list</replaceable> ) ] }
        <literal>from</literal>
        { <replaceable class="parameter">'filename'</replaceable> | program <replaceable class="parameter">'command'</replaceable> | stdin | pstdin }
        [ [ with ] ( <replaceable class="parameter">option</replaceable> [, ...] ) ]
        [ where <replaceable class="parameter">condition</replaceable> ]</literal></term>

        <term><literal>\copy { <replaceable class="parameter">table</replaceable> [ ( <replaceable class="parameter">column_list</replaceable> ) ] | ( <replaceable class="parameter">query</replaceable> ) }
        <literal>to</literal>
        { <replaceable class="parameter">'filename'</replaceable> | program <replaceable class="parameter">'command'</replaceable> | stdout | pstdout }
        [ [ with ] ( <replaceable class="parameter">option</replaceable> [, ...] ) ]</literal></term>

        <listitem>
        <para>
        Performs a frontend (client) copy. This is an operation that
        runs an <acronym>SQL</acronym> <link linkend="sql-copy"><command>COPY</command></link>
        command, but instead of the server
        reading or writing the specified file,
        <application>psql</application> reads or writes the file and
        routes the data between the server and the local file system.
        This means that file accessibility and privileges are those of
        the local user, not the server, and no SQL superuser
        privileges are required.
        </para>

        <para>
        When <literal>program</literal> is specified,
        <replaceable class="parameter">command</replaceable> is
        executed by <application>psql</application> and the data passed from
        or to <replaceable class="parameter">command</replaceable> is
        routed between the server and the client.
        Again, the execution privileges are those of
        the local user, not the server, and no SQL superuser
        privileges are required.
        </para>

        <para>
        For <literal>\copy ... from stdin</literal>, data rows are read from the same
        source that issued the command, continuing until a line containing
        only <literal>\.</literal>
        is read or the stream reaches <acronym>EOF</acronym>. This option is useful
        for populating tables in-line within an SQL script file.
        For <literal>\copy ... to stdout</literal>, output is sent to the same place
        as <application>psql</application> command output, and
        the <literal>COPY <replaceable>count</replaceable></literal> command status is
        not printed

Title: psql Meta-Commands: \close, \conninfo, \copy
Summary
This section continues detailing psql meta-commands. \close closes a specified prepared statement, utilizing the extended query protocol. \conninfo displays information about the current database connection, including TLS details. \copy performs a frontend copy operation, allowing data transfer between a server and the local file system or a program executed by psql, using the local user's privileges.