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
Here's a single line example for importing users using the header row of a csv:
echo "\copy users ($(head -1 users.csv)) FROM 'users.csv' DELIMITER ',' CSV HEADER" | psql
Or with gzip:
echo "\copy users ($(gzip -dc users.csv.gz | head -1)) FROM PROGRAM 'gzip -dc users.csv.gz' DELIMITER ',' CSV HEADER" | psql