我试图让一个简单的数据库查询正常工作,但我无法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)))
关于如何将集合传递给查询的任何想法?
直接在下面运行查询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>
如果它有所不同,我正在使用:org.clojure/clojure 1.4.0、org.clojure/java.jdbc 0.2.3 和 mysql/mysql-connector-java 5.1.6。