문제

I have this column "timestamp" in table A, and I want to select all data but the last week, here is my R code but an error pop up saying "Error in function (classes, fdef, mtable) : unable to find an inherited method for function "dbWriteTable", for signature "MySQLConnection", "data.frame", "character"", any help would be appreciated? THANK YOU.

fun <- function(con, dat.set, tbl.name) {

if (dbExistsTable(con, tbl.name)) {     
BFWeek = dbGetQuery(con, statement=paste("SELECT * FROM A",
"WHERE timestamp < timestampadd(day, -7, now())"))   
dbWriteTable(con, BFWeek, tbl.name, row.names=F, append=T);            

} else { 
dbWriteTable(con, tbl.name, dat.set, row.names=F, append=T); 
  }
} 

fun(conn_table, df, "A")
도움이 되었습니까?

해결책

The name of the table has to come before the data frame you want to write to that table. In the else part of your code, you seem to have the order correct, but in the if part you have BFWeek before tbl.name where it should go after.

> showMethods("dbWriteTable")
Function: dbWriteTable (package DBI)
conn="MySQLConnection", name="character", value="character"
conn="MySQLConnection", name="character", value="data.frame"

This would have given you an idea as to which methods are available and which are not.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top