Using Copy to import

suggest change

To Copy Data from a CSV file to a table

COPY <tablename> FROM '<filename with path>';

To insert into a table named user from a file named user_data.csv in /home/user/:

COPY "user" FROM '/home/user/user_data.csv';

USER is a reserved word, so the table name has to be quoted. The path is on the database server.

To Copy data from pipe separated file to table

COPY "user" FROM '/home/user/user_data' WITH (DELIMITER '|');

If you omit DELIMITER, the default delimiter is a tab in text format, not a comma. A comma is the default only for FORMAT csv.

To ignore header line while importing file

Use the Header option:

COPY "user" FROM '/home/user/user_data' WITH (FORMAT csv, DELIMITER '|', HEADER);

HEADER is allowed only with CSV format. In CSV, the default quote character is a double quote. If the file uses another quote character, set QUOTE. That option is also CSV-only.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents