R: Why does dbWriteTable fail when table exists despite 'append = TRUE'

This solution was listed by the author in the question and has been moved here.

It appears the bug/feature only occurs when a full table path is used such as myDB.temp_table compared to simply temp_table

> dbWriteTable(conn=open_connection, name='myDB.temp_table', value=summary_data_final, overwrite=FALSE, append=TRUE, row.names=0)
Error in mysqlExecStatement(conn, statement, ...) : 
  RS-DBI driver: (could not run statement: Table 'temp_table' already exists)
[1] FALSE
Warning message:
In mysqlWriteTable(conn, name, value, ...) :
  could not create table: aborting mysqlWriteTable

> dbWriteTable(conn=open_connection, name='temp_table', value=summary_data_final, overwrite=FALSE, append=TRUE, row.names=0)
[1] TRUE

I haven't found this documented anywhere and am surprised that I haven't come across it before.


Just use this function to insert a row in your table

 insert_row <- function(jconn,table_name,col_data,data){
  dbSendUpdate(jconn,paste0("INSERT INTO ",table_name," (",paste0(col_data,collapse=','),") VALUES ('",paste0(data,collapse="','"),"');"))
  print('data inserted')}

Tags:

Mysql

R