db.connect: Create a connection to a database

Description Usage Arguments Value Note Author(s) See Also Examples

View source: R/db_conn-generic.R

Description

Create a connection to a PostgreSQL or Greenplum (Pivotal) database. One can create multiple connections to multiple databases. The connections are indexed by an integer starting from 1.

Usage

1
2
3
db.connect(host = "localhost", user = Sys.getenv("USER"), dbname = user,
password = "", port = 5432, madlib = "madlib", conn.pkg = "RPostgreSQL",
default.schemas = NULL, verbose = TRUE, quick = FALSE)

Arguments

host

A string, default is "localhost". The name or IP of the host where the database is located.

user

A string, default is the user's username. The username used to connect to the database.

dbname

A string, default is the same as the username. The name of the database that you want to connect to.

password

A string, default is "". The password string used to connect to the database.

port

An integer, default is 5432. The port number used to connect to the database.

madlib

A string, default is "madlib". The name of the schema where MADlib is installed.

conn.pkg

A string, default is "RPostgreSQL". The name of the R package used to connect to the database. Currently, only RPostgreSQL is supported, but the support for other packages such as RODBC can be easily added.

default.schemas

A string, default is NULL. The search path or default schemas of the database that you want to use. The string must be a set of schema names separated by commas. One can also use db.default.schemas or db.search.path to display or set the search path in the database.

verbose

A logival value, default is TRUE, whether to print some information while connecting to the database.

quick

A logical value, default is FALSE. Whether to skip some of the argument checks to speed up the creation of the connection. Useful when using this function inside a function, where you have already validate all the arguments. It is not recommended to set this value to TRUE when you are using this function directly.

Value

An integer, the ID number for the newly created connection.

Note

Right only MADlib 0.6 or later is supported. If you have an older version of MADlib, you will not be able to use all the functions whose names start with "madlib.". However you can still use all the other functions.

Also, right now only PostgreSQL and Greenplum databases are supported.

Author(s)

Author: Predictive Analytics Team at Pivotal Inc.

Maintainer: Frank McQuillan, Pivotal Inc. [email protected]

See Also

db.disconnect disconnects a connection.

db.list lists all active connections.

connection info the functions that extract information about the connection.

conn.eql tests whether two connections are the same.

db.search.path and db.default.schemas displays or sets the search path (i.e. default schemas) in the connected database.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Not run: 
## connect to a database


## set up the database connection
## Assume that .port is port number and .dbname is the database name
cid <- db.connect(port = .port, dbname = .dbname, verbose = FALSE)

db.disconnect(cid, verbose = FALSE)

## End(Not run)

PivotalR documentation built on May 30, 2017, 8:18 a.m.