在将变量粘贴到RMariaDB的查询字符串中时出现问题。我可以在没有粘贴的情况下返回查询,并在我查询的数据帧中找到适当的where语句(例如,MIN)。当我试图在查询中使用一个变量时,它失败了。我上下搜索了stackoverflow,并阅读了dbgetquery文档,但似乎什么都没有起作用。我确信它是简单的东西,只是似乎找不到它。
library(RMariaDB)
team <- "MIN"
# This returns entire database with MIN in tm column.
filename <- dbGetQuery(conn, "select * from nhl_lab_lines_today")
# These will all give me a [1054] error.
test <- paste("select * from nhl_lab_lines_today WHERE tm = ",paste(team,collapse=", "),sep ="")
test <- paste("select * from nhl_lab_lines_today WHERE tm = team")
test <- paste("select * from nhl_lab_lines_today WHERE tm =", team,sep=" ")
filename <- dbGetQuery(conn, test)

发布于 2020-02-10 14:48:11
dbGetQuery(con, paste0("select * from nhl_lab_lines_today WHERE tm = '", team ,"'"))https://stackoverflow.com/questions/60144108
复制相似问题