COPY -- copy data between a file and a table
COPY moves data between PostgreSQL tables and standard file-system files. COPY TO copies the contents of a table to a file, while COPY FROM copies data from a file to a table (appending the data to whatever is in the table already). COPY TO can also copy the results of a SELECT query.
If a list of columns is specified, COPY will only copy the data in the specified columns to or from the file. If there are any columns in the table that are not in the column list, COPY FROM will insert the default values for those columns.
COPY with a file name instructs the PostgreSQL server to directly read from or write to a file. The file must be accessible to the server and the name must be specified from the viewpoint of the server. WhenSTDIN or STDOUT is specified, data is transmitted via the connection between the client and the server.
A utilização do comando copy na mais básica forma pode ser aplicada dessa forma:
COPY 'name_table' [name_column, name_column2]
TO 'C:\temp\name.type'
USINGDELIMITERS ',';
Pode-se copiar dados uma tabela inteira, ou apenas alguns campos da tabela caso você queira especifique-os em [name_column].
O arquivo será copiado no diretório que for especificado no destino "TO 'C:\...\...'
Outro comando interessante é o COPY FROM.
Este, copia registros consistentes em um arquivo distinto, diferenciando os registros pelo delimitador que é declarado na expressão:
COPY 'C:\temp\client.txt'
FROM nome_table (columns)
USING DELIMITERS ',';