Fork me on GitHub
#sql
<
2019-09-04
>
Bingen Galartza Iparragirre10:09:53

I want to update a column for multiple rows in one jdbc call. This is what I tried (jdbc/update! spec :appuser {:org-id org-id} ["id in ?" user-ids]), where user-ids is a vector of uuids. But I get the following error: Can't infer the SQL type to use for an instance of clojure.lang.PersistentVector. Use setObject() with an explicit Types value to specify the type to use Does anyone know what could be wrong?

Bingen Galartza Iparragirre10:09:23

I found this workaround, but I guess there is a better way of doing it.

Bingen Galartza Iparragirre10:09:39

(let [where-clause-str (str "id in (" (clojure.string/join ", " (take (count user-ids) (repeat "?"))) ")")
        where-clause (cons where-clause-str user-ids)
        {:keys [success? processed-values]} (sql-utils/sql-update! spec logger :appuser {:org-id org-id} where-clause)]

Bingen Galartza Iparragirre12:09:56

I had to extend the clojure.java.jdbc/ISQLParameter as shown there, and also change id in ? to id = any(?)