我的问题是
(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一起使用?
最佳答案
如果需要原始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))
看起来科尔马也做了同样的事情:
(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 (?, ?))"
关于postgresql - 使用Korma运行原始sql时,如何在准备好的语句中传递clojure向量?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20417184/