Closed owen-audience-republic closed 1 year ago
Since you want just the :rows
, you would do better calling next.jdbc.result-set/datafiable-result-set
(on the result of .getColumns
, passing tx
as the connectable and an options hash map), then calling datafy
on that (and removing the :rows
selector).
The default datafication of a ResultSet
-- after you've required next.jdbc.datafy
-- is going to attempt to call getters on the ResultSet
object and some database drivers, unfortunately, do strange things on what should be purely readonly operations on object state. Looking at the stack trace above, it's hard to tell whether that's bad behavior by the PG driver or by HikariCP -- but the net result is that calling the (unimplemented feature) getHoldability
marked the Connection
as bad.
Since metadata doesn't change (unless you're actively applying DDL changes while your app is running), you might do better to precalculate the metadata once at startup and cache it -- and use a plain PG Connection
that you get from next.jdbc
, independent of the HikariCP pool.
I'll leave this open until you've verified my suggestion about calling datafiable-result-set
, but there's not much next.jdbc
can do about bad driver/pooling behavior in cases like this.
This does work:
(defn simple-table-schema-ii
"If table-name exists, return its schema as a sequence ({:name \"oid\" :type \"bigserial\"})"
[tx table-name]
(let [schema (-> tx
.getMetaData
(.getColumns nil "public" table-name nil)
rs/datafiable-result-set
clojure.datafy/datafy)]
(map #(hash-map :name (:COLUMN_NAME %) :type (:TYPE_NAME %)) schema)))
Thankyou very much.
I'm trying to put together a function to report back on table schema in PostgreSQL. It is throwing an exception which looked reportworthy. I swear this exact function has also worked without error, so there is some sort of configuration problem at play - I'm not sure what though.
This isn't a huge problem for me, I'll rewrite the function to do the same thing in a different way. But I thought documenting the problem somewhere would be helpful.
tx
is acom.zaxxer.hikari.pool.HikariProxyConnection
wrapping anorg.postgresql.jdbc.PgConnection
. Running that on a table causes the following exception (edited out the top of the stack trace):This was on postgres 9.6.3, running on linux, Clojure 1.11.1, jdbc.next 1.2.796 &
[org.postgresql/postgresql "42.2.16"]
.