dharma017
6/13/2017 - 5:08 AM

Copy from CSV file to PostgreSQL table with headers in CSV file.

Copy from CSV file to PostgreSQL table with headers in CSV file.

Copy from CSV file to PostgreSQL table with headers in CSV file.

COPY wheat FROM 'wheat_crop_data.csv' DELIMITER ';' CSV HEADER

The only way to express relative path with client permissions is using STDIN,

When STDIN or STDOUT is specified, data is transmitted via the connection between the client and the server.

Feed the file via STDIN

  psql -h remotehost -d remote_mydb -U myuser -c \
   "copy mytable (column1, column2) from STDIN with delimiter as ','" \
   < ./relative_path/file.csv