Skip to content

Instantly share code, notes, and snippets.

@dharma017
Created June 13, 2017 05:08
Show Gist options
  • Save dharma017/30f0dc13447c40c003e3df3dc91c0556 to your computer and use it in GitHub Desktop.
Save dharma017/30f0dc13447c40c003e3df3dc91c0556 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment