August 28, 2013

RからPostgreSQLへアクセスする


library("RPostgreSQL")

con <- dbConnect(PostgreSQL(), 

                 user= "username", 

                 password="password", 

                 dbname="dbname",

                 host="127.0.0.1",

                 port="5432")



rs <- dbSendQuery(con,

                  "select * from tablename")

data <- fetch(rs, n = -1)

簡単ですね。

© gepuro 2013

Slideshare Icon from here , Home Icon from icons8