This topic describes how to use the \COPY command to export data from an AnalyticDB for PostgreSQL instance to your computer.

Comparison between \COPY and COPY

  • Similarities:

    The syntax of both is identical. For more information about the syntax, see COPY.

  • Differences:
    • \COPY is used on psql, but COPY is used on databases.
    • \COPY can be used to manage FILE, STDIN, and STDOUT files, but COPY can be used to manage only STDIN and STDOUT files.
      Note You must have the SUPERUSER permission to modify FILE files, but AnalyticDB for PostgreSQL does not support this permission.

Syntax:

The following example shows how to run the \COPY command to export data from an AnalyticDB for PostgreSQL instance to your computer:

            \COPY {table [(column [, ...])] | (query)} TO {'file' | STDOUT}
            [ [WITH] 
            [OIDS]
            [HEADER]
            [DELIMITER [ AS ] 'delimiter']
            [NULL [ AS ] 'null string']
            [ESCAPE [ AS ] 'escape' | 'OFF']
            [CSV [QUOTE [ AS ] 'quote'] 
            [FORCE QUOTE column [, ...]] ]
            [IGNORE EXTERNAL PARTITIONS ]
Note AnalyticDB for PostgreSQL also allows you to use JDBC to execute the COPY statement. The CopyIn method is encapsulated within JDBC. For more information, see Interface CopyIn.

Example

 \COPY test1 TO '/path/to/localfile';

References

Use the \COPY command to import or export on-premises data