I have a data frame containing columns 'Quarter' having values like "16/17 Q1", "16/17 Q2"... and 'Vendor' having values like "a", "b"... .
I am trying to write this data frame into database using
query <- paste("INSERT INTO cc_demo (Quarter,Vendor) VALUES(dd$FY_QUARTER,dd$VENDOR.x)")
but it is throwing error :
Error in .local(conn, statement, ...) :
could not run statement: Unknown column 'dd$FY_QUARTER' in 'field list'
I am new to Rmysql, Please provide me some solution to write entire dataframe?
I would advise against writing sql query when you can actually use very handy functions such as
dbWriteTable
from theRMySQL
package. But for the sake of practice, below is an example of how you should go about writing the sql query that does multiple inserts for aMySQL
database:You should get:
You can provide this query to your database connection in order to run it.
I hope this helps.