Learn R Programming

RPostgreSQL (version 0.2-0)

dbConnect-methods: Create a connection object to an PostgreSQL DBMS

Description

These methods are straight-forward implementations of the corresponding generic functions.

Arguments

Side Effects

A connection between R/S-Plus and an PostgreSQL server is established. The current implementation supports up to 100 simultaneous connections.

References

See the Database Interface definition document DBI.pdf in the base directory of this package or http://stat.bell-labs.com/RS-DBI.

See Also

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

Examples

Run this code
# create an PostgreSQL instance and create one connection.
drv <- dbDriver("PostgreSQL")

# open the connection using user, passsword, etc., as
con <- dbConnect(drv, dbname = "postgres")

# Run an SQL statement by creating first a resultSet object
rs <- dbSendQuery(con, statement = paste(
                      "SELECT itemCode, itemCost, itemProfit",
                      "FROM sales",
                      "SORT BY itemName"));

# we now fetch records from the resultSet into a data.frame
df <- fetch(rs, n = -1)   # extract all rows
dim(df)

Run the code above in your browser using DataLab