Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying data from local .CSV file to pgsql table in remote server

Tags:

postgresql

I am trying to copy data from a csv file from my local machine into a remote pgsql table named states, but i am getting an ERROR: Syntax error at or near "FROM". Can someone guide me as to why i am receiving this error?

   COPY FROM STDIN states FROM '/Users/Shared/data.csv'  DELIMITER AS ',';
like image 523
Micheal C. Avatar asked Mar 11 '23 19:03

Micheal C.


1 Answers

The problem is that the path to the file is in the remote server, not the local one.

you need psql and pipe the file to STDIN:

psql -h host -d remoteDB -U myuser -c  "copy states from STDIN with delimiter as ',';" < /path/file.csv

alternatively you can also do:

cat /path/file.csv | psql -h host -d remoteDB -U myuser -c  "copy states from STDIN with delimiter as ',';"
like image 144
dmg Avatar answered Apr 27 '23 20:04

dmg