Difference between importing data from a local file and the Internet to postgresql? (Rails)

StackOverflow https://stackoverflow.com/questions/23548891

Вопрос

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?

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top