I have a function I made to get the name of a table and the one or more columns and create the table in postgres sql. I created a static version as well to test. The static version works fine, however the dynamic verison only worked when I wrote it only to take one column as an argument. Now that I'm trying to have multiple columns as an arg it throws an exception. Here is the code:
(require '[clojure.java.jdbc :as j]
'[clojure.java.jdbc.sql :as s])
(def db
{:classname "org.postgresql.Driver"
:subprotocol "postgresql"
:subname "mydb"
:username "username"
:password "password"})
(defn StaticCreateTable
[]
(j/with-connection db
(j/create-table "records3"
["RecID", "int", "PRIMARY KEY"]
["TreeID", "int"]
["Bubba", "varchar(30)"])
(println "Success!")))
(defn DynamicCreateTable2
[map]
(j/with-connection db
(j/create-table (:tablename map) (for [i (:columns map)] i))
(println "Success!")))
This is what I input:
(DynamicCreateTable2 {:tablename "Creators3"
:columns [
["CreatorID", "int", "PRIMARY KEY"]
["Number", "int"]]} )
Any help would be greatly appreciated