db_writeTable: write a data to a table in an (open) database

View source: R/dbAccess.R

db_writeTableR Documentation

write a data to a table in an (open) database

Description

write a data to a table in an (open) database

Usage

db_writeTable(
  db,
  tableName,
  theTable,
  primaryKeyName = defaultPrimaryKey(),
  overwrite = FALSE,
  append = !overwrite,
  doNotChangePool = FALSE,
  row.names = FALSE
)

Arguments

db

database access 'handle'

tableName

name of the table

theTable

data.frame containing data

primaryKeyName

name of the primary key if used (default = "id_")

overwrite

boolean if TRUE, the data overwrites the existing table (default = FALSE)

append

boolean if TRUE (default) the data is appended to the existing table

doNotChangePool

boolean that sets whether the pool has to be locked/ released inside this function. Usually this needs to be done, so default is FALSE. Set to TRUE if this locking/release is done outside of the function. Note that there is a sort of bug when working with the pool::dbWriteTable : when a sql constraint like UNIQUE is defined for the table used, this may result in a locked database upon error. It's advisable to set doNotChangePool to TRUE to prevent this from happening

row.names

by default FALSE, defines if row names of the theTable should be included or not

Value

nothing

Note

both append & overwrite will generate errors if used wrongly

if colnum names of the table do not match the column names of the data.frame, then execution will stop

data.frame columns of type list will not write properly to eg MySQL, use function ... in stead of this one. SQLite works without problems

the overwrite = TRUE option has been found to 'destroy' foreign key constraints. This is probably because a table is redefined/ reinitialized when a table is 'overwritten'. Use with care


BenBruyneel/BBPersonalR documentation built on Aug. 23, 2024, 8:28 p.m.