9

My table has a NOT NULL column called 'created' with DEFAULT CLOCK_TIMESTAMP(). My CSV file from which I am copying intentionally does not have a column called 'created' because I want the database to use the default value for it. My copy command is:

\copy table_name from '/local/path/to/file.csv' delimiter ',' CSV HEADER

The error I receive is:

missing data for column "created_"

The PostgreSQL documentation says: "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."

Thanks for any help

1 Answer 1

10

The clue is in the "that are not in the column list".

You need to specify the "column list" for this to work and leave out the one with the default value:

\copy table_name (column1, column2, ...) from '/local/path/to/file.csv' delimiter ',' CSV HEADER
Sign up to request clarification or add additional context in comments.

1 Comment

That did the trick - I thought the HEADER keyword just told it to use the CSV header columns as my list. Maybe I'll send a documentation clarification request...

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.