just wondering if there's any way to pass an arbitrary number of parameters to an IN clause via params of dbGetQuery()
for example, given either
dbcon <- dbConnect(RPostgres::Postgres())
# or: dbcon <- dbConnect(RPostgreSQL::PostgreSQL())
dbExecute(dbcon, "CREATE TEMP TABLE foo AS SELECT i FROM generate_series(1, 10) x(i);")
can I do anything like:
dbGetQuery(dbcon, "SELECT * FROM foo WHERE i IN (1, 2, 3)")
where the identifiers is a "short list of values", i.e. normally less than 10 integers or strings. I thought I might be able to do something like:
ids <- c(1, 2, 3)
dbGetQuery(dbcon, "SELECT * FROM foo WHERE i IN $1", list(ids))
but the best I can do is:
ids <- '{1,2,3}'
dbGetQuery(dbcon, "SELECT * FROM foo WHERE i = ANY($1)", list(ids))
but then generating ids from a set of strings is somewhat error prone.