Home Explore Blog CI



postgresql

17th chunk of `doc/src/sgml/ref/psql-ref.sgml`
e4070c3a03c3feef80028bc4170ea04ab404a82b9610c5140000000100000fa1
 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 (since it might be confused with a data row).
        To read/write <application>psql</application>'s standard input or
        output regardless of the current command source or <literal>\o</literal>
        option, write <literal>from pstdin</literal> or <literal>to pstdout</literal>.
        </para>

        <para>
        The syntax of this command is similar to that of the
        <acronym>SQL</acronym> <link linkend="sql-copy"><command>COPY</command></link>
        command.  All options other than the data source/destination are
        as specified for <command>COPY</command>.
        Because of this, special parsing rules apply to the <command>\copy</command>
        meta-command.  Unlike most other meta-commands, the entire remainder
        of the line is always taken to be the arguments of <command>\copy</command>,
        and neither variable interpolation nor backquote expansion are
        performed in the arguments.
        </para>

        <tip>
        <para>
        Another way to obtain the same result as <literal>\copy
        ... to</literal> is to use the <acronym>SQL</acronym> <literal>COPY
        ... TO STDOUT</literal> command and terminate it
        with <literal>\g <replaceable>filename</replaceable></literal>
        or <literal>\g |<replaceable>program</replaceable></literal>.
        Unlike <literal>\copy</literal>, this method allows the command to
        span multiple lines; also, variable interpolation and backquote
        expansion can be used.
        </para>
        </tip>

        <tip>
        <para>
        These operations are not as efficient as the <acronym>SQL</acronym>
        <command>COPY</command> command with a file or program data source or
        destination, because all data must pass through the client/server
        connection.  For large amounts of data the <acronym>SQL</acronym>
        command might be preferable.
        </para>
        </tip>

        </listitem>
      </varlistentry>

      <varlistentry id="app-psql-meta-command-copyright">
        <term><literal>\copyright</literal></term>
        <listitem>
        <para>
        Shows the copyright and distribution terms of
        <productname>PostgreSQL</productname>.
        </para>
        </listitem>
      </varlistentry>


      <varlistentry id="app-psql-meta-commands-crosstabview">
        <term><literal>\crosstabview [
            <replaceable class="parameter">colV</replaceable>
            [ <replaceable class="parameter">colH</replaceable>
            [ <replaceable class="parameter">colD</replaceable>
            [ <replaceable class="parameter">sortcolH</replaceable>
            ] ] ] ] </literal></term>
        <listitem>
        <para>
        Executes the current query buffer (like <literal>\g</literal>) and
        shows the results in a crosstab grid.
        The query must return at least three columns.
        The output column identified by <replaceable class="parameter">colV</replaceable>

Title: psql Meta-Commands: \copy (Continued), \copyright, \crosstabview
Summary
Continuing the description of the \copy meta-command, it explains the usage of stdin/stdout and pstdin/pstdout options. It also highlights the parsing rules specific to \copy. It provides tips on alternative methods and efficiency considerations compared to the SQL COPY command. Then, it introduces \copyright which displays the copyright information for PostgreSQL, and \crosstabview, which executes the current query buffer and presents the results in a crosstab grid format.