This topic describes how to use the \copy command to export data from an AnalyticDB for PostgreSQL instance to your computer.
Precautions
Data Management (DMS) does not support the \copy command. To use the \copy command, we recommend that you use psql to connect to your instance. For more information about how to use psql for connection, see Client connection.
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.
NoteYou 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 ]
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.
Examples
\COPY test1 TO '/path/to/localfile';
References
Use the \copy command to import data from your computer to AnalyticDB for PostgreSQL