Wednesday, May 30, 2012

R Postgresql

Reading from PostgreSQL DB

  1. Install RPostgreSQL
    :library(RPostgreSQL)
  2. Open a db connection using the dbConnect function
    :con<-dbConnect(PostgreSQL(),user="xxx", password="xxx",host="localhost", client.flag=CLIENT_MULTI_RESULTS)
  3. Use dbGetQuery to initiate a SELECT and return the result sets
    :sql<-"SELECT * FROM table WHERE name='xxx'"
    :rows<- dbGetQuery(con,sql)
  4. Use dbDisconnect to terminate the connection
    :dbDisconnect(con)

No comments:

Post a Comment