문제

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