if (FALSE) {
# create an PostgreSQL instance and set 10000 of rows per fetch.
library(RPostgreSQL)
drv <- dbDriver("PostgreSQL", fetch.default.records=10000)
# Connecting to PostgreSQL with the specified parameters
con <- dbConnect(drv,user="usrname",password="passwd",dbname="postgres")
# Running the query to obtain the resultset
rs <- dbSendQuery(con, "select * from cities where population > 5000")
# fetch records into a dataframe.
# n = 50 fetched fifty records
df <- fetch(rs, n = 50)
# n = -1 fetches all the remaining records available
df2 <- fetch(rs, n = -1)
# Clearing the result set
dbClearResult(rs)
#This returns a character vector (possibly of zero-length)
# table names available on the con connection.
dbListTables(con)
}
Run the code above in your browser using DataLab