I saw a post some time ago answering this question, and here are three 
solutions.  I thought the first would be the most elegant.  But for some 
reason, the first does not work, and returns an empty set.  I'm trying to 
understand what's wrong with it.
(defn get-by-ids-test
  [ids]
  (let [qs (string/join "," (repeat (count ids) "?"))
        sql (str "select * from survey where survey_id in (" qs ")")]
    (println "SQL " sql)
    (println "ids" ids)
    (sql/with-connection (get-db-spec)
      (sql/with-query-results results
        [sql ids]
        (into [] results)))))

(defn get-by-ids-test-2
  [ids]
  (sql/with-connection (get-db-spec)
    (sql/with-query-results results
      [(str "select * from survey where survey_id in (" (apply str 
(interpose \, ids)) ")")]
      (into [] results))))

(defn get-by-ids-test-3
  [ids]
  (sql/with-connection (get-db-spec)
    (sql/with-query-results results
      [(str "select * from survey where survey_id in (" (string/join "," 
ids)  ")")]
      (into [] results))))

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Reply via email to