我在将值传递到dbSendQuery时遇到困难。
下面是我的代码:

参数:

date_param <- '2014_02_02'


查询:

  pull <- dbSendQuery(test_db, "select distinct product_id, group
                                 from test_table
                                 where date between date_sub(",date_param,", interval 1 year) and ",date_param," ;")

pulled_data <- fetch(pull, n=-1)


我得到的错误是:

Error in is(object, Cl) :
  internal error in RS_DBI_getResultSet: could not find resultSet in connection


我的语法有问题吗?

谢谢。

最佳答案

您需要将SQL语句合并为一个字符串。现在,您将各个部分作为单独的参数传递。尝试使用paste()进行声明。

pull <- dbSendQuery(test_db, paste("select distinct product_id, group
                             from test_table
                             where date between date_sub(",date_param,", interval 1 year) and ",date_param," ;"))

08-20 00:43