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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -