0

I am exporting a dataframe from R to MySQL with the following command

sqlSave(con1,test_data, "prices",safer=FALSE,rownames=TRUE,addPK=TRUE)

My dataframe has four columns with numeric data (stock prices) and the date column is the row names. Now when I export this to MySQl all is fine. However, when in MySQL I rename the rownames as follows:

ALTER TABLE `test`.`prices` 
CHANGE COLUMN `rownames` `date` DATE NULL DEFAULT NULL;

I obtain the following error when I want to save the updated version of the data

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

For replication here is a snapshot of my dataframe

row.names   A   B   C   D
1987-12-31  247.08  NA  648.13  21564.00
1988-01-29  257.07  NA  635.95  23622.32
1988-02-29  267.82  NA  708.88  25242.81
1988-03-31  258.89  NA  701.56  26260.26
1988-04-29  261.33  NA  710.55  27434.12

What is the problem and how can I solve this?

user2157086
  • 525
  • 1
  • 5
  • 20
  • please read [this](http://stackoverflow.com/questions/13575180/how-to-change-the-language-of-errors-in-r) on how you change the error to English. – agstudy Oct 04 '14 at 12:12
  • After the `ALTER` sql statement you have a MySQL table with a column named `date`. You are trying to save a data frame to that table, but the data frame has no column named `date`, so that column is missing. In other words, when saving to an existing MySQL table, the column names of the MySQL table must match the column names of the data frame. – jlhoward Oct 04 '14 at 18:31

0 Answers0