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
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;