在R SQL查询中传递多个参数

mrwjdhj3  于 2023-07-31  发布在  其他
关注(0)|答案(1)|浏览(123)

我试图在R SQL查询中多次传递相同的参数。查询为:

  1. table_x <- c(‘Rain’, Cloudy’)
  2. df <- dbGetQuery(conn, "select schemaname, tablename, dateupdated, test_result from weather
  3. Where dateupdated in (select max(dateupdated) from weather where conditions in (?,?))
  4. and dateupdated = sysdate
  5. and conditions in (?,?)",
  6. params= table_x)

字符串
如果我删除第二个条件子句,查询就可以工作。否则它会抱怨
查询需要4个参数;提供2个
我试着创建另一个向量,并将其与第一个向量沿着传递,但仍然得到相同的错误。任何建议。
谢啦,谢啦

k5ifujac

k5ifujac1#

对于查询中找到的每个?,必须在params=中有一个参数。顺序很重要,所以params=c(table_x, table_x)应该可以工作。

  1. df <- dbGetQuery(conn, "
  2. select schemaname, tablename, dateupdated, test_result
  3. from weather
  4. where dateupdated in (select max(dateupdated) from weather where conditions in (?,?))
  5. and dateupdated = sysdate
  6. and conditions in (?,?)",
  7. params = c(table_x, table_x))

字符串

相关问题