Let me mention a solution that AFAIK only works in Postgres. Postgres has arrays, and you can pass the string representation of '{1,2,3}'. IN can be replaced by ANY (in fact, in some situations, PG processes the IN request internally, according to the output of the scheduler. An array can be created with a loop entirely on the client side and then passed as a string, voila.
source share