Class03 Answer:

Download S&P 500 prices from Yahoo, load them into table called prices.

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.


Class03 Lab


ml4.us About Blog Contact Class01 Class02 Class03 Class04 Class05 Class06 Class07 Class08 Class09 Class10 dan101 Forum Google Hangout Vboxen