你如何在clojure/java.jdbc中使用"WHERE x IN y"子句?

dsm*_*dsm 5 mysql jdbc clojure

我试图让一个简单的数据库查询工作,但我不能clojure/java.jdbc从一个IN条款中选择.

代码如下所示:

(sql/with-connection db
  (sql/with-query-results rows
    ["select  f.name        name
          ,   f.id          file_id
      from    FileCategory  fc
      join    File          f
          on  fc.file       = f.id
      where   fc.category   in ?
      having  count(1)      >= ?"
     [1 2]    ; This is the bit which does not work.
              ; I have tried (to-array) and (set) too
     2]
    (into [] rows)))
Run Code Online (Sandbox Code Playgroud)

关于如何将集合传递给查询的任何想法?

直接在mysql我下运行查询没有问题:

mysql> select f.name, f.id from FileCategory fc join File f on fc.file = f.id where fc.category in (1, 2) having count(1) >= 2;
+-----------+----+
| name      | id |
+-----------+----+
| some name |  1 |
+-----------+----+
1 row in set (0.02 sec)

mysql> 
Run Code Online (Sandbox Code Playgroud)

如果它有所不同我正在使用:org.clojure/clojure 1.4.0,org.clojure/java.jdbc 0.2.3和mysql/mysql-connector-java 5.1.6.

Esa*_*ija 0

尝试这个:

(sql/with-connection db
  (sql/with-query-results rows
    ["select  f.name        name
          ,   f.id          file_id
      from    FileCategory  fc
      join    File          f
          on  fc.file       = f.id
      where   fc.category   in (?, ?)
      having  count(1)      >= ?"
     1 2 2]
    (into [] rows)))
Run Code Online (Sandbox Code Playgroud)