dbWriteTable(…, append = T) is overwritng in R

2019-04-05 08:35发布

I am using RJDBC for accessing MySQL from R. Earlier I used to work with RMySQL which is not available for R 2.15. There were so many discussions around SO but still I couldn't able to use RMySQL package in R 2.15 so switched to RJDBC.

When I'm using dbWriteTable(..., append = T) command for appending records into MySQL table it is simply overwriting, please see the code below.

setting environment variable for MySQL server

Sys.setenv(MYSQL_HOME='C:/Program Files (x86)/MySQL/MySQL Server 5.1')

library(RJDBC)

MySQL connection

drv <- JDBC("com.mysql.jdbc.Driver","mysql-connector-java-5.0.5.jar", "`")
conn <- dbConnect(drv, "Retail", user="root", password="abc")
..................
..................
..................
dbWriteTable(conn, "Customer_Tbl", x, row.names=F,append = T)

Customer_Tbl is overwriting everytime instead of appending.

Can somebody help in how to tackle this issue?

Thanks Suresh

1条回答
戒情不戒烟
2楼-- · 2019-04-05 09:26

You need to use overwrite=FALSE, following sample code:

dbWriteTable(connection, name=tableName, value=rows , append=T, row.names=F, overwrite=F);
查看更多
登录 后发表回答