This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-28
Channels
- # announcements (3)
- # babashka (36)
- # beginners (77)
- # boot (3)
- # chlorine-clover (10)
- # cider (27)
- # clj-kondo (1)
- # cljs-dev (4)
- # clojure (256)
- # clojure-belgium (1)
- # clojure-europe (9)
- # clojure-uk (18)
- # clojuredesign-podcast (9)
- # clojurescript (54)
- # cryogen (8)
- # cursive (3)
- # data-science (1)
- # datomic (2)
- # duct (31)
- # events (1)
- # exercism (3)
- # fulcro (116)
- # joker (20)
- # kaocha (5)
- # meander (2)
- # nrepl (4)
- # off-topic (10)
- # other-languages (15)
- # re-frame (18)
- # reagent (4)
- # shadow-cljs (44)
- # sql (14)
- # tools-deps (17)
Hi, I am trying to update a table in a postgres db with next-jdbc using the update! fn as follows:
(defn ->table [s]
(let [_ (debug (str "->table:" s))]
(str/replace s #"-" "_")))
(defn ->col [s]
(let [_ (debug (str "->col:" s))]
(str/replace
(str/replace s #"-" "")
#"\."
"_")))
(defn update-tasks [db tasks]
(let [ds (jdbc/get-datasource db)
results (f/try*
(doseq
[t tasks]
(sql/update! ds :my-tasks t {:table-fn ->table
:column-fn ->col})))]
(if (f/failed? results)
results
tasks)))
but get this exception:
Can't infer the SQL type to use for an instance of api.resources.db$__GT_table. Use setObject() with an explicit Types value to specify the type to use.
org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of vms_api.resources.db$__GT_table. Use setObject() with an explicit Types value to specify the type to use.
at org.postgresql.jdbc.PgPreparedStatement.setObject (PgPreparedStatement.java:978)
I'm not sure, how the :table-fn is getting down into the postgres jdbc driver as a value. I am using this successfully with an insert! fn that looks almost identical.
Am I doing something wrong here?@pdmct You have the wrong arguments to update!
It takes a connectable (`ds`), a table (`:my-tasks`), a map of updates (`t`), a where map or clause -- which is missing -- and then then options.
update!
takes one more argument than insert!
🙂
(I must admit, I was confused by that error message at first!)
yes, that isn't obvious , I have been scratching my head for while on this. so some more like this:
(sql/update! ds :analytics-tasks t {:id (:id t)}
{:table-fn ->table
:column-fn ->col}))
Yup, that will perform the update WHERE id = ?
... (:id t)
The problem is that it couldn't tell the difference between the map {:id (:id t)}
and the map {:table-fn ->table :column-fn ->col}
since both are maps and options are ... optional.
So even next.jdbc.specs
couldn't have helped you here.