This topic describes how to run the \copy command on the psql CLI client to import text files from your computer to an AnalyticDB for PostgreSQL instance.
Precautions
The \copy command cannot be used to import large amounts of data in parallel because the \copy command writes data in series by using the coordinator node. If you need to import large amounts of data in parallel, you can use the data import method based on Object Storage Service (OSS). For more information about how to use OSS to import data, see Migrate data by using an OSS external table.
Syntax
The following example demonstrates how to run the \copy command to import data to an AnalyticDB for PostgreSQL instance:
\COPY table [(column [, ...])] FROM {'file' | STDIN}
[ [WITH]
[OIDS]
[HEADER]
[DELIMITER [ AS ] 'delimiter']
[NULL [ AS ] 'null string']
[ESCAPE [ AS ] 'escape' | 'OFF']
[NEWLINE [ AS ] 'LF' | 'CR' | 'CRLF']
[CSV [QUOTE [ AS ] 'quote']
[FORCE NOT NULL column [, ...]]
[FILL MISSING FIELDS]
[[LOG ERRORS [INTO error_table] [KEEP]
SEGMENT REJECT LIMIT count [ROWS | PERCENT] ]
Examples
\COPY test1 FROM '/path/to/localfile';