clojure.java.jdbc/insert - Unable to insert a sequence of vectors dynamically for batch insert into sql -


this question has answer here:

i trying insert sequence of vectors rows in sql using clojure.java.jdbc/insert! function takes in input given in :

http://clojure-doc.org/articles/ecosystem/java_jdbc/using_sql.html#inserting-data

i unable map on sequence of vectors (["a" 1 "c"] ["b" 2 "d"] ["d" 3 "e"]....) dynamically mapping on since uses following syntax

(j/insert! db-spec :fruit          nil ; column names not supplied          [1 "apple" "red" 59 87]          [2 "banana" "yellow" 29 92.2]          [3 "peach" "fuzzy" 139 90.0]          [4 "orange" "juicy" 89 88.6]) 

i want able insert dynamically sql batch insert. how can this? tia.

you can using apply (which apply entire list of args args j/insert! function)

(def args-list '([1 "apple" "red" 59 87]                  [2 "banana" "yellow" 29 92.2]                  [3 "peach" "fuzzy" 139 90.0]                  [4 "orange" "juicy" 89 88.6] ...))  (apply j/insert! db-spec :fruit args-list) 

Comments