saveSQLDataFrame: Save SQLDataFrame object as a new database table.

Description Usage Arguments Details Value Examples

View source: R/saveSQLDataFrame.R

Description

The function to save SQLDataFrame object as a database table with a supplied path to database. It also returns a SQLDataFrame object constructed from the user-supplied dbname, dbtable, and dbkey.

Usage

1
2
3
4
5
6
7
8
9
saveSQLDataFrame(
  x,
  dbname = tempfile(fileext = ".db"),
  dbtable = deparse(substitute(x)),
  localConn = connSQLDataFrame(x),
  overwrite = FALSE,
  index = TRUE,
  ...
)

Arguments

x

The SQLDataFrame object to be saved.

dbname

A character string of the file path of to be saved SQLite database file. Will only be used when the input SQLDataFrame represents a SQLite database table. Default to save in a temporary file.

dbtable

A character string for the to be saved database table name. Default is the name of the input SQLDataFrame.

localConn

A MySQL connection with write permission. Will be used only when the input SQLDataFrame objects connects to MySQL connections without write permission. A new MySQL table will be written in the the database this argument provides.

overwrite

Whether to overwrite the dbtable if already exists. Only applies to the saving of SQLDataFrame objects representing SQLite database tables. Default is FALSE.

index

Whether to create the database index. Default is TRUE.

...

other parameters passed to methods.

Details

For SQLDataFrame from union or rbind, if representation of MySQL tables, the data will be sorted by key columns, and saved as MySQL table in the connection with write permission.

Value

A SQLDataFrame object.

Examples

1
2
3
4
5
6
7
test.db <- system.file("extdata/test.db", package = "SQLDataFrame")
conn <- DBI::dbConnect(DBI::dbDriver("SQLite"), dbname = test.db)
obj <- SQLDataFrame(conn = conn, dbtable = "state", dbkey = "state")
obj1 <- obj[1:10, 2:3]
obj1 <- saveSQLDataFrame(obj1, dbtable = "obj_subset")
connSQLDataFrame(obj1)
dbtable(obj1)

SQLDataFrame documentation built on Nov. 29, 2020, 2:01 a.m.