Importing CSVs in Postgres does not use headerinformation in csv file

Sep 20, 2019 00:00 · 104 words · 1 minute read database programming

The COPY command in Postgres, which can be used to import data from csv files, does not use the Headerline to assign values to columns. See https://www.postgresql.org/docs/current/sql-copy.html. Especially in cases where you have a ton of datafields in your CSV file you could avoid to specify the order in which the data is arranged, by hand.

This means that the command must have the following form

COPY <tablename>[columnvalues] FROM <csvfile> CSV HEADER;

I’m aware a small script, that generates the COPY-Command is programmed in no time. However, it seems like unnecessary work to do if postgres has already all infomation it needs in place.

If you want to get in touch with me, send me an email

longo.tomas@googlemail.com