0

使用 RPostgreSQL 包,我必须在以下位置使用 a 进行vector查询string

dbGetQuery(con, "select from id_table where id_user in tmp")

长度= 10k的列表或向量应该在哪里tmp,我该怎么做?谢谢。

4

2 回答 2

1

试试这个:

query = sprintf("select * from id_table where id_user in (%s)", paste("'",tmp, "'",collapse=","))

dbGetQuery(con, query)

希望这可以帮助。

于 2015-06-19T14:49:28.000 回答
0

您可以使用 paste0。这是我采用 state.abb 数据集的示例

valid_state_logic=paste0("(",paste0("'",state.abb,"'", collapse=","),")")

print(valid_state_logic)
[1] "('DC','AL','AK','AZ','AR','CA','CO','CT','DE','FL','GA','HI','ID','IL','IN','IA','KS','KY','LA','ME','MD','MA','MI','MN','MS','MO','MT','NE','NV','NH','NJ','NM','NY','NC','ND','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VT','VA','WA','WV','WI','WY')"
于 2015-06-19T14:23:49.503 回答