sendData: Copy data to database tables

sendDataR Documentation

Copy data to database tables

Description

These functions copy data frames to database tables

Usage

sendData(db, data, table = deparse(substitute(data)), ...)

## S4 method for signature 'CredentialsList,data.frame'
sendData(db, data, table, ..., applyFun = lapply)

## S4 method for signature 'Credentials,data.frame'
sendData(db, data, table, chunkSize = Inf, ...)

## S4 method for signature 'DBIConnection,data.frame'
sendData(db, data, table = deparse(substitute(data)), ...)

## S4 method for signature 'MySQLConnection,data.frame'
sendData(db, data, table, ..., mode = "insert")

## S4 method for signature 'MariaDBConnection,data.frame'
sendData(db, data, table, ..., mode = "insert")

Arguments

db

one in:
(Credentials) the credentials to get a connection to a database.
(DBIConnection) DBIConnection-class
(MySQLConnection) MySQLConnection-class

data

A data.frame (or coercible to data.frame)

table

A character string specifying a DBMS table name

...

arguments passed to methods and to reTry

applyFun

(function) something like lapply or mclapply

chunkSize

An integer specifying the number of rows send to the db at a time. Defaults to Inf.

mode

One of "insert", "replace", or "truncate"

Details

Basically, these functions are intended to behave like dbWriteTable. However, there are two notebale exceptions:

  1. append is always set to TRUE, i.e. the target database table must be created or already exist before sendData is called

  2. row.names is always set to FALSE, i.e., row.names must be converted to a variable if you want to keep them

There are four different modes for sending data to the database:

insert

INSERT INTO TABLE, i.e. in case of duplicates only the first entry will be kept

replace

REPLACE INTO TABLE, i.e. in case of duplicates only the last entry will be kept

truncate

like dbWriteTable with argument overwrite = TRUE, i.e., the table is truncated before sending the data

update

like insert but falls back to update on duplicate key


INWT/dbtools documentation built on Aug. 21, 2022, 9:37 p.m.