Postgres CSV COPY from/import is not respecting CSV headers

前端 未结 3 636
北恋
北恋 2021-01-04 08:51

I\'m trying to import data from CSV into the table. The issue is that even with CSV HEADER, the CSV is being imported based on the column index, not on the head

3条回答
  •  粉色の甜心
    2021-01-04 09:50

    The COPY command by default copies columns from a CSV file in the default order of the columns in the table. The HEADER option on input is ignored, it basically only informs the backend to ignore the first line on input. If the order of the columns in the CSV does not match the order of the columns in the table, you can explicitly specify the column order to match the layout of the CSV file:

    COPY churches (id,denomination_id,name,address_id)
    FROM '$PWD/data/Data - Churches.csv'
    WITH DELIMITER ',' CSV HEADER;
    

提交回复
热议问题