Fork me on GitHub
#luminus
<
2016-09-20
>
v4705:09:31

Hi, I'm seeing this error when passing a vector to be written to a Postgresql jsonb column: org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of clojure.lang.PersistentVector. I'm not sure why the type and protocol extensions in db.core are not handling this. Maps work fine. Any ideas?

yogthos14:09:46

@shanekilkelly that looks like it just might be chrome cache, try clearing it and see if the issue goes away

shanekilkelly14:09:25

this was with the +postgres and +scss switches

yogthos14:09:58

hmm the +scss switch might affect it, it might not have been updated to use the latest css for bootstrap 4

yogthos14:09:10

@v47 I think you might need to update this

(extend-type clojure.lang.IPersistentVector
  jdbc/ISQLParameter
  (set-parameter [v ^java.sql.PreparedStatement stmt ^long idx]
    (let [conn      (.getConnection stmt)
          meta      (.getParameterMetaData stmt)
          type-name (.getParameterTypeName meta idx)]
      (if-let [elem-type (when (= (first type-name) \_) (apply str (rest type-name)))]
        (.setObject stmt idx (.createArrayOf conn elem-type (to-array v)))
        (.setObject stmt idx (to-pg-json v))))))

v4720:09:28

@yogthos Yup, that was it, thanks! When the type is extended for ISQLParameter, is the ISQLValue protocol extension superfluous?

(extend-protocol jdbc/ISQLValue
       IPersistentMap
       (sql-value [value] (to-pg-json value))
       IPersistentVector
       (sql-value [value] (to-pg-json value)))

yogthos20:09:07

Yeah I think so