With PostgreSQL, I was able to use the ANY comparison and bind the collection to an array to achieve this.
public interface Foo {
@SqlQuery("SELECT id FROM foo WHERE name = ANY (:nameList)")
List<Integer> getIds(@BindStringList("nameList") List<String> nameList);
}
@BindingAnnotation(BindStringList.BindFactory.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
public @interface BindStringList {
String value() default "it";
class BindFactory implements BinderFactory {
@Override
public Binder build(Annotation annotation) {
return new Binder<BindStringList, Collection<String>>() {
@Override
public void bind(SQLStatement<?> q, BindStringList bind, Collection<String> arg) {
try {
Array array = q.getContext().getConnection().createArrayOf("varchar", arg.toArray());
q.bindBySqlType(bind.value(), array, Types.ARRAY);
} catch (SQLException e) {
// handle error
}
}
};
}
}
}
NB: ANY is not part of the ANSI SQL standard, so this creates a hard dependency on PostgreSQL.