rpg (version 1.6)

copy_from: Bulk read and write

Description

Read from and write to a database using COPY

Usage

copy_from(what, psql_opts = "")

copy_to(x, tablename, schemaname = NULL, append = FALSE, psql_opts = "")

Arguments

what

a table name or sql query string

psql_opts

passed directly to the psql command line

x

a data frame

tablename

name of table to create

schemaname

create table in this schema

append

if false, drop and receate table

Details

These functions use the SQL COPY command and therefore are much faster than write_table and possibly read_table. These functions also call PostgreSQL's psql command from the command line and will fail if it is not found on the search path.

Because these functions shell out to psql you do not need an active connection. By specifying psql_opts you can connect to any database without affecting the active connection. If you do not specify psql_opts an attempt will be made to use the active connection information. If that fails, psql will use default connection settings.

See Also

set_default_password

Examples

# NOT RUN {
# example requires hflights
if (! require(hflights, quietly = TRUE))
 stop("This example requires the \'hflights\' package")

# big dataset
data(hflights)
dim(hflights)

system(paste("createdb rpgtesting"))

opts = paste("-d rpgtesting")
system.time(copy_to(hflights, psql_opts = opts))
system.time(invisible(copy_from("hflights", psql_opts = opts)))

connect("rpgtesting")
begin()

## Sloooowwwwwww
## system.time(write_table(hflights))
system.time(invisible(read_table("hflights")))

rollback()
disconnect()
dropdb("rpgtesting")
# }
# NOT RUN {
# }