0

I have five columns. Out of these, am not able to insert column TagName into my database using RMySQL. The various methods I have used are:

sql <- sprintf("insert into Tags (Id, TagName, Count, ExcerptPostId, WikiPostId) values (%d, '%s', %d, %d, %d);", Id, TagName, Count, ExcerptPostId, WikiPostId)

Output: Error in sprintf("insert into Tags (Id, TagName, Count, ExcerptPostId, WikiPostId) values (%d, '%s', %d, %d, %d);", : unsupported type

query <- paste("INSERT INTO Tags (Id, TagName, Count, ExcerptPostId, WikiPostId) VALUES(",Id, "," , TagName, "," ,Count, "," ,ExcerptPostId, "," , WikiPostId, ")")

Output: Error in .local(conn, statement, ...) : could not run statement: Unknown column 'sms' in 'field list' Here, 'sms' is the first value of TagName column

dbWriteTable(con, "Tags", table)

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

I am using R version 3.1.2 (2014-10-31)

timekeeper
  • 698
  • 15
  • 37

1 Answers1

0

On your second attempt

query <- paste("INSERT INTO Tags (Id, TagName, Count, ExcerptPostId, WikiPostId)
    VALUES(",Id, "," , TagName, "," ,Count, "," ,ExcerptPostId, "," , WikiPostId, ")")

You should enclose the TagName by single quotes, like this:

query <- paste("INSERT INTO Tags (Id, TagName, Count, ExcerptPostId, WikiPostId)
    VALUES(",Id, ",'" , TagName, "'," ,Count, "," ,ExcerptPostId, "," , WikiPostId, ")")

(mind the single quotes!)

uri2x
  • 3,162
  • 1
  • 11
  • 25
  • 1
    Thanks a lot. I knew I had to put the single quotes but I wasn't able to place it in the correct place. You saved my day. Not enough rep to upvote, but will do once I get enough. – timekeeper Sep 05 '15 at 10:22