fetch-methods: Fetch records from a previously executed query

Description Details Methods References See Also Examples

Description

This method is a straight-forward implementation of the corresponding generic function.

Details

The RPostgreSQL implementations retrieves only n records, and if n is missing it only returns up to fetch.default.rec as specified in the call to PostgreSQL (500 by default).

Methods

res

an PostgreSQLResult object.

n

maximum number of records to retrieve per fetch. Use n = -1 to retrieve all pending records; use a value of n = 0 for fetching the default number of rows fetch.default.rec defined in the PostgreSQL initialization invocation.

...

currently not used.

References

See the Database Interface definition document DBI.pdf in the base directory of this package or https://cran.r-project.org/package=DBI.

See Also

PostgreSQL, dbConnect, dbSendQuery, dbGetQuery, dbClearResult, dbCommit, dbGetInfo, dbReadTable.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## Not run: 
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, user = "ruser",password = "123456",dbname = "status")
res <- dbSendQuery(con, statement = paste(
                      "SELECT w.category, w.cost, p.type",
                      "FROM items w, sales P",
                      "WHERE w.category = p.type",
                      "ORDER BY w.cost"))
# we now fetch the first 100 records from the resultSet into a data.frame
data1 <- fetch(res, n = 100)   
dim(data1)

dbHasCompleted(res)

# let's get all remaining records
data2 <- fetch(res, n = -1)

## End(Not run)

RPostgreSQL documentation built on May 2, 2019, 8:49 a.m.