Friday 18 December 2009

Connecting R and Postgres via JDBC

I need to make a note of this for reference:

library( RJDBC ) 
postgres <- JDBC( "org.postgresql.Driver", "/path/to/postgresql-8.3-604.jdbc4.jar")
con <- dbConnect(postgres, "jdbc:postgresql://localhost:5432/mydbname", user = "myusername", password = "xxx" )

From here on, I can read

my.r.df <- dbReadTable( con, "myschema.mytablename" )

and save

dbWriteTable( con, "myschema.mytablename", my.r.df )

No comments:

Post a Comment