0

我的查询类似于

(def list [1,2,3,4])

(def result (exec-raw
   ["SELECT * from table_name where table_id in (?)"],[list] :results))

我不断收到这个错误,Clojure 无法推断持久向量的 SQL 类型,使用 setObject 来告诉类型,现在如何将 setObject 与 CLojure 一起使用?

4

2 回答 2

3

如果你想要一个原始的 sql,你需要连接“?”:

(def list ["AAPL" "GOOG"])
(def questions
  (->> (repeat (count list) "?")
       (interpose ",")
       (apply str)))

(def q (str "SELECT * FROM ta_indicators WHERE ticker IN ("
            questions ")"))

(println (exec-raw [q list] :results))

看起来 korma 做同样的事情并且有效:

(defentity ta_indicators)
(-> (select* ta_indicators)
    (fields :ticker)
    (where {:ticker [in ["GOOG" "TSLA"]]})
    (as-sql))

;; "SELECT \"ta_indicators\".\"ticker\" FROM \"ta_indicators\" WHERE (\"ta_indicators\".\"ticker\" IN (?, ?))"
于 2013-12-06T08:17:15.143 回答
1

Shouldn't the function be called like so:

(exec-raw ["select ..." list] ...)

You might have list in the wrong place.

于 2013-12-06T07:46:52.193 回答