1
votes

I want to populate one column in a postgres table from a CSV file.

I am trying this command in postgres 9.5.5 -

\copy myschema.items(name) from items.csv;

and get this error -

ERROR: null value in column "item_code" violates not-null constraint DETAIL: Failing row contains..... CONTEXT: COPY items, line 1: "some value"

Is postgres trying to populate all columns from the CSV and complains because it does not find ones with non null constraints in the CSV? How do I tell postgres not to worry about other columns and instead just copy the name column stated in the command into the table?

1

1 Answers

2
votes

Two errors there:

  • Put the file name in single quotes.

  • Add (FORMAT 'csv')