我有五列。其中,我无法使用RMySQL将列TagName插入到我的数据库中。 我使用的各种方法是:
sql <- sprintf("insert into Tags (Id, TagName, Count, ExcerptPostId, WikiPostId) values (%d, '%s', %d, %d, %d);", Id, TagName, Count, ExcerptPostId, WikiPostId)
输出:sprintf中的错误(“插入标签(Id,TagName,Count,ExcerptPostId,WikiPostId)值(%d,'%s',%d,%d,%d);”,: 不支持的类型
query <- paste("INSERT INTO Tags (Id, TagName, Count, ExcerptPostId, WikiPostId) VALUES(",Id, "," , TagName, "," ,Count, "," ,ExcerptPostId, "," , WikiPostId, ")")
输出:.local(conn,statement,...)出错: 无法运行语句:'字段列表'中的未知列'sms' 这里,'sms'是TagName列的第一个值
dbWriteTable(con, "Tags", table)
输出:(函数(classes,fdef,mtable)中的错误: 无法为签名'“MySQLConnection”,“character”,“matrix”找到函数'dbWriteTable'的继承方法'
我正在使用R版本3.1.2(2014-10-31)
答案 0 :(得分:0)
第二次尝试
query <- paste("INSERT INTO Tags (Id, TagName, Count, ExcerptPostId, WikiPostId)
VALUES(",Id, "," , TagName, "," ,Count, "," ,ExcerptPostId, "," , WikiPostId, ")")
您应该用单引号括起TagName,如下所示:
query <- paste("INSERT INTO Tags (Id, TagName, Count, ExcerptPostId, WikiPostId)
VALUES(",Id, ",'" , TagName, "'," ,Count, "," ,ExcerptPostId, "," , WikiPostId, ")")
(请注意单引号!)