我有一个函数来获取表的名称和一个或多个列,并在 postgres sql 中创建表。我也创建了一个静态版本来测试。静态版本可以正常工作,但是动态版本仅在我编写它只是为了将一列作为参数时才有效。现在我正在尝试将多个列作为 arg,它会引发异常。这是代码:
(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!")))
这是我输入的:
(DynamicCreateTable2 {:tablename "Creators3"
:columns [
["CreatorID", "int", "PRIMARY KEY"]
["Number", "int"]]} )
任何帮助将不胜感激