2

I have a database whereas the first column is labeled as serial not null primary key. The table creation and automatic sequence table creation is successful. However, whenever I do:

copy <table_name> from '/path/to/file' delimiter ',' CSV HEADER;

PostgreSQL tries to read my first column into the serial column, which fails because my first column in my CSV file contains characters (not an integer).

How can I tell the COPY command to populate using a serial column as the first column?

1 Answer 1

3

I determined that if I specified the header names and named my columns exactly like the header names in my CSV file, that the import worked:

copy <table_name>(column1, column2, etc) from '/path/to/file' delimiter ',' CSV HEADER;
Sign up to request clarification or add additional context in comments.

1 Comment

It's the same behaviour as INSERT.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.