2

I'm trying to upload files to a PostgreSQL database from my local computer, the error I get is:

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not open file "C:\Mar-2015.csv" for reading: No such file or directory

The command that I'm trying to run is:

pcon = 'postgresql://user:password@ipaddress:5432/dbname::tablename'
path = os.path.normpath(
       'C:/Mar-2015.csv'))
o.odo(path, pcon, sep='|')

It looks like PostgreSQL is trying to find the file on the remote server rather than on the local machine. Running the script on the server (and changing the file path to a location on the server) runs fine, which seems to confirm my suspicion.

Is it possible to use odo to upload a file from my local machine to a remote PostgreSQL machine? I'm using Amazon RDS.

QuinRiva
  • 679
  • 1
  • 7
  • 14

1 Answers1

1

I had a similar issue using odo to load a CSV to a PostgreSQL database but inside Docker containers. You're right, odo looks for the file in the host of the PostgreSQL database. I managed to make this work mounting the folder to the same path in the client and the server containers.

To solve your problem you can use scp to upload the file to your server and the running the Python script, you'll need SSH access to your server

scp /path/to/local/file username@remote:/path/to/server/file

Then running your script as usual.