Sophie
Sophie

Reputation: 97

How to resolve this error--dbWriteTable()

I successfully connected to MYSQL DB and tried to write my result back to the database: dbWriteTable(con,"predicted min",forecast$min) where forecast$min is just a vector of doubles.

I got this error message:

Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘dbWriteTable’ for signature ‘"MySQLConnection", "character", "numeric"’

I guess I need a dataframe object for my third parameter, so then I tried this: dbWriteTable(con,"predicted min",data.frame(min=forecast0.1$min))

But got this error:

Error in .local(conn, statement, ...) : could not run statement: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '( row_names text, min double )' at line 2

I'm using SQLyog. I don't know if that's related to this problem. Any suggestions? Thanks in advance.

Sophie

Upvotes: 3

Views: 6543

Answers (1)

Josh W.
Josh W.

Reputation: 1123

SQLyog is not related to this issue. If your table only has one column (min), then you need not write the row names of the dataframe to the table. Try:

dbWriteTable(con,"predicted min",data.frame(min=forecast0.1$min), row.names = FALSE, append = TRUE)

Or else you're inserting a tuple with with two values into a table with one column. If the table already exists and you don't want to overwrite the table, you should also have append = TRUE.

edit: The table name should not have a space in it.

Upvotes: 3

Related Questions