Problems with RODBC sqlSave

后端 未结 6 903
轻奢々
轻奢々 2021-02-14 17:39

I\'m having some difficulty inserting a data frame into a mySql database using RODBC. Below is the code I\'m using:

data <- data.frame(analysedDataID=c(1,2,3         


        
6条回答
  •  长发绾君心
    2021-02-14 18:21

    Very old question I know, but I had (and solved for my instance) the same problem just now, getting this error

    Error in odbcUpdate(channel, query, mydata, coldata[m, ], test = test,  : 
      missing columns in 'data'
    

    from using

    sqlSave(
    

    In the rodbc package.

    I solved it by setting

    ,fast = F
    

    If anyone else from the first google results lands here, hope this helps

    EDIT: So I since have looked at this more. When setting the flag to "F" as I recommend below you insert the rows, row by row into the database. While it was "T" it would fail if one row was incorrect, but now that row fails and you don't know about it. So the data base may be missing data that you thought was in there. Check the count of rows in the data base vs the number of rows you expect to be inserted from your dataframe. You probably have a single value that is incompatible. What I have taken to doing now is using "paste" function in a loop to create a string like "insert into tableName values("eg1","eg2") " this way I can get error messages back about why it did not go into the database

提交回复
热议问题