如何将数据帧d
的值传递到内部的postgresql语句中,如下所示:
a<-data.frame(b=sample(letters),c=1:26)
d<-a%>%filter(c>15)%>%select(b)
e<-paste("select date,amount from table where id in ('", d,"')")
dbGetQuery(con,e)
错误消息:
Error in postgresqlExecStatement(conn, statement, ...) :
RS-DBI driver: (could not Retrieve the result : ERROR: invalid input syntax for integer: "c("m","w"...)
LINE 1: ...type,id from table where id in ('c("m","w"...
获取上述查询错误。如果我错了,建议我。
答案 0 :(得分:0)
这是您传递给Cannot iterate over string ("2")
的内容:
dbGetQuery
您需要“折叠” paste("select date,amount from table where id in ('", d,"')")
[1] "select date,amount from table where id in (' u ')" "select date,amount from table where id in (' i ')"
[3] "select date,amount from table where id in (' s ')" "select date,amount from table where id in (' t ')"
[5] "select date,amount from table where id in (' k ')" "select date,amount from table where id in (' l ')"
[7] "select date,amount from table where id in (' y ')" "select date,amount from table where id in (' v ')"
[9] "select date,amount from table where id in (' n ')" "select date,amount from table where id in (' z ')"
[11] "select date,amount from table where id in (' b ')"
变量以获取类似(“ value1”,“ value2”,...)的信息:
d