I have a CSV file with two columns: city and zipcode. I want to be able to copy this file into a PostgreSQL table using the copy command and at the same time auto generate the id value.
The table has the following columns: id, city, and zipcode.
My CSV file has only: city and zipcode.
The COPY command should do that all by itself if your table uses a
serialcolumn for theid:So you should be able to say:
and the
idwill be generated as usual. If you don’t have aserialcolumn forid(or a manually attached sequence), then you could hook up a sequence by hand, do your COPY, and then detach the sequence.