I started this lab by calling curl:
cd ~ curl -L ml4.us/csv/GSPC.csv > /tmp/gspc.csv
Next, I wrote a SQL script:
-- -- fillprices.sql -- -- This script should Download S&P 500 prices from Yahoo, load them into table called prices. -- Demo: -- curl -L ml4.us/csv/GSPC.csv > /tmp/gspc.csv -- ~ann/madlib_demos/psqlmad -af fillprices.sql DROP TABLE IF EXISTS prices; CREATE TABLE prices ( cdate date ,openp float ,highp float ,lowp float ,closep float ,adjp float ,volume float ); COPY prices ( cdate ,openp ,highp ,lowp ,closep ,adjp ,volume ) FROM '/tmp/gspc.csv' WITH CSV HEADER;
Then, I ran the SQL script:
~ann/madlib_demos/psqlmad -af fillprices.sql
Be aware that when Postgres runs the COPY command it relies on the Postgres server process.
That process needs the full path to the CSV file.
Often when I work with the COPY command, I put the CSV file in /tmp.
Then, the server can easily find the CSV file.