0
我有一個函數來獲取表名和一列或多列,並在postgres sql中創建表。我也創建了一個靜態版本來測試。靜態版本可以正常工作,但動態版本只有在我只寫一列作爲參數時才起作用。現在我試圖將多個列作爲arg引發異常。下面是代碼:通過Clojure JDBC動態創建表的函數不起作用
(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"]]})
任何幫助,將不勝感激
謝謝你做的伎倆,我原本有(:列地圖),但在使用前,它仍然無法正常工作。我很感激它的噪音! – user1321988 2013-05-13 03:16:15