1

Im trying to append a dataframe I have manipulated in R to a simple MySQL database with an existing table (table_a) with four columns as follows:

id. Primary key and auto incrementing.
name. varchar(45).
value_a. varchar(45).
value_b. varchar(45).

The dataframe (data) has three columns.
name.
value_a.
value_b.

I can connect to the database OK using RMySQL and dbConnect. But when I use the dbWriteTable command to append the dataframe "data" I get the following error.

Error in .local(conn, statement, ...) :
could not run statement: Unknown column 'row_names' in 'field list'

I know it connects ok because i can get it to create a new table but i want to continually append to an existing one in MySQL.

Any ideas anyone.

con <- dbConnect(MySQL(),
                 user = 'root',
                 password = '???????',
                 host = 'localhost',
                 dbname='rdbtest')
dbWriteTable(conn = con, name = 'table_a', value = data, append = TRUE, header = TRUE)

1 Answer 1

1

Ok solved.. needed to add row.names=FALSE

con <- dbConnect(MySQL(),
                 user = 'root',
                 password = '???????',
                 host = 'localhost',
                 dbname='rdbtest')
dbWriteTable(conn = con, name = 'table_a', value = data, append = TRUE, header = TRUE, row.names = FALSE)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.