Automatically exported from code.google.com/p/rpostgresql Synopis RPostgreSQL provides a DBI-compliant database connection from GNU R to PostgreSQL.
Development of RPostgreSQL was supported via the Google Summer of Code 2008 program.
The package is now available on the CRAN mirror network and can be installed via install.packages() from within R.
A mailing list rpostgresql-dev@googlegroups.com is available at Google Groups as rpostgresql-dev; it is also mirrored at Gmane.org.
Summary of basic usage
drv <- dbDriver("PostgreSQL") 2.dbConnect(drv,...) creates and opens a connection to the database implemented by the driver drv. Connection string should be specified with parameters like user, password, dbname, host, port, tty and options. For more details refer to the documentation. Eg.
con <- dbConnect(drv, dbname="tempdb") 3.dbListConnection(drv, ...) provides List of connections handled by the driver Eg.
dbListConnections(drv) 4.dbGetInfo(dbObject, ...) and summary(dbObject) returns information about the dbObject (driver, connection or resultSet). Eg.
dbGetInfo(drv) summary(con) 5.dbSendQuery(con, statement, ...) submits one statement to the database. Eg.
rs <- dbSendQuery(con,"select * from TableName") 6.fetch(rs,n, ...) fetches the next n elements from the result set. Eg.
fetch(rs,n=-1) ## return all elements fetch(rs,n=2) ##returns last 2 elements in record set.
dbGetQuery(con,"select * from TableName")
dbGetException(con)
dbListResults(con)
dbListTables(con)
dbExistsTable(con,"TableName")
dbRemoveTable(con,"TableName")
dbListFields(con,"TableName")
dbColumnInfo(rs)
dframe <-dbReadTable(con,"TableName").
dbWriteTable(con,"newTable",dframe)
dbGetStatement(rs)
dbGetRowsAffected(rs)
dbHasCompleted(rs) 20.dbGetRowCount(res, ...) returns number of rows fetched so far. Eg.
dbGetRowCount(rs) 21.dbBeginTransaction begins the PostgreSQL transaction. dbCommit commits the transaction while dbRollback rolls back the transaction. Returns a logical indicating whether the operation succeeded or not. Eg.
dbBeginTransaction(con) dbRemoveTable(con,"newTable") dbExistsTable(con,"newTable") dbRollback(con) dbExistsTable(con,"newTable")
dbBeginTransaction(con) dbRemoveTable(con,"newTable") dbExistsTable(con,"newTable") dbCommit(con) dbExistsTable(con,"newTable")
dbClearResult(rs)
dbDisconnect(con)
dbUnloadDriver(drv) Example library(RPostgreSQL)
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, dbname="R_Project")
rs <- dbSendQuery(con, "select * from R_Users")
fetch(rs,n=-1)
dbGetQuery(con, "select * from R_packages")
dbDisconnect(con)
dbUnloadDriver(drv) For any queries, suggestions or bugs, please contact the mailing list stated above.