Inserting PostgreSQL arrays with Clojure

后端 未结 3 1208
情话喂你
情话喂你 2021-02-04 10:25

I can\'t find a way to insert Postgres\' array type with Clojure.

(sql/insert! db :things {:animals [\"cow\" \"pig\"]})

Didn\'t work which I ki

3条回答
  •  滥情空心
    2021-02-04 10:53

    A similar strategy that I've been using:

    (defn vec->arr [array-vector]
      (.createArrayOf (j/get-connection db) "varchar" (into-array String array-vector)))
    
    (extend-protocol j/ISQLValue
        clojure.lang.IPersistentVector
        (sql-value [v]
        (vec->arr v)))
    

提交回复
热议问题