zio / zio-jdbc

A small, idiomatic ZIO interface to JDBC.
Apache License 2.0
82 stars 64 forks source link

Support multiple IN interpolation in queries #152

Closed gaeljw closed 11 months ago

gaeljw commented 1 year ago

Follow-up issue of https://github.com/zio/zio-jdbc/issues/104 solved in v0.1.0.

I tried to use the interpolation in a query that contains two IN clauses and fails whereas having a single IN clause works.

Example of query:

val field1List: List[String] = List("a", "b")
val field2List: List[Int] = List(2, 3)
val startDate: String = ???
val endDate: String = ???

sql"""SELECT group_id, count(*) as my_count
        FROM my_table
        WHERE date >= $startDate AND date < $endDate
        AND field1 IN ($field1List)
        AND field2 IN ($field2List)
        GROUP BY group_id"""
  .query[(Long, Long)]
  .selectAll

The error I get is:

Parameter "#6" is not set; SQL statement:
  SELECT group_id, count(*) as my_count
                  FROM my_table
                  WHERE date >= ? AND date < ?
                  AND field1 IN (?, ?)
                  AND field2 IN (?, ?)
                  GROUP BY group_id [90012-220]
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:658)

If I remove one of the IN clauses, it does work.

lvitaly commented 11 months ago

I faced the same issue with v0.1.1.