I am trying to upload a data frame to a table in sql server using sqlSave(). This dataframe has a timestamp in it and I\'d like to map the timestamp col to
Two options:
1) Lazy one: let the error occur, the table will be created, and change the column(s) to datetime manually in your database. It will work the next time.
2) Correct: use varTypes
Note that your problem can be stripped down by removing unnecessary stuff. As an aside, I probably would not use the column name timestamp in an sql server, because I have seen confusions because of the internal timestamp data type is totally different.
library(RODBC)
mdf = data.frame(timestamp=as.POSIXct(Sys.time()))
varTypes = c(timestamp="datetime")
channel = odbcConnect("test")
sqlSave(channel,mdf,rownames=FALSE,append=TRUE,varTypes=varTypes)
close(channel)