Postgres CSV COPY from/import is not respecting CSV headers

前端 未结 3 637
北恋
北恋 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:28

    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
    

提交回复
热议问题