Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mysql

r

analytics

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

like image 950
AVSuresh Avatar asked Jul 30 '12 10:07

AVSuresh


1 Answers

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

dbWriteTable(connection, name=tableName, value=rows , append=T, row.names=F, overwrite=F);
like image 111
Annie Avatar answered Oct 17 '22 21:10

Annie