'PostgreSQL: Import CSV file not containing id primary key

I'm trying to import a big CSV file like below:

psql -U postgres -d opendata -c " \
  COPY foos \
  FROM '/tmp/foos.csv' \
  DELIMITER '|' \
  CSV \
  HEADER"

But it doesn't contain the first id column of my table.

How should I better deal with it ?

Is there an option to autofill this column ? Should add add the id at the beginning of each line of my file ?



Solution 1:[1]

We can try to declare clear columns name without id primary key by COPY command

For COPY FROM, each field in the file is inserted, in order, into the specified column. Table columns not specified in the COPY FROM column list will receive their default values.

COPY foos ( column_name [, ...])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 D-Shih