Skip to content
Prev 1116 / 1559 Next

append=TRUE, overwrite=FALSE ignored in dbWriteTable

On Thu, Oct 27, 2011 at 7:11 AM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
Here is a second alternative.  Instead of inserting the new records
one by one this one writes the new records all at once to a temporary
table, tmp, and then inserts them en masse into the existing bod table
and finally drops the temporary table at the end.

library(RpgSQL)

con <- dbConnect(pgSQL())

## write BOD into bod table
if (dbExistsTable(con, "bod")) dbSendUpdate(con, "drop table bod")
dbWriteTable(con, "bod", BOD)

## insert NEW into tmp table, insert that into bod and drop tmp
NEW <- 2*BOD
if (dbExistsTable(con, "tmp")) dbSendUpdate(con, "drop table tmp")
dbWriteTable(con, "tmp", NEW)
dbSendUpdate(con, "insert into bod select * from tmp")
dbSendUpdate(con, "drop table tmp")

## show result
dbGetQuery(con, "select * from bod")

dbDisconnect(con)