Question

I have created a rake task to import a .csv file into my postgresql database.

In it, this code works:

conn = PGconn.open(:dbname => 'mydbname')
conn.exec("COPY valuations FROM '/Users/Username/Downloads/avroll.csv' DELIMITER ',' CSV HEADER")

This does not work:

conn = PGconn.open(:dbname => 'mydbname')
conn.exec("COPY valuations FROM 'https://s3-us-west-2.amazonaws.com/mydirectory/myfile.csv' DELIMITER ',' CSV HEADER")

I've confirmed that the file is downloadable at that URL in my browser.

Why does this work for a local file, but not from a file that is at a given URL? How can I correct it?

Était-ce utile?

La solution

COPY is only for local files. http://www.postgresql.org/docs/9.1/static/sql-copy.html

COPY moves data between PostgreSQL tables and standard file-system files.

You can however download the file via Ruby and then pass the location to your COPY command.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top