Fork me on GitHub
#sql
<
2024-03-21
>
hanDerPeder19:03:37

I have a postgres table with a jsonb column that I want to return directly to clients. Is it possible to just pass the data through withouth next.jdbc touching it? we have this guy installed which I don't want to be executed in this case

(extend-protocol rs/ReadableColumn
  PGobject
  (read-column-by-label [^PGobject v _]
    (<-pgobject v))
  (read-column-by-index [^PGobject v _2 _3]
    (<-pgobject v)))

seancorfield20:03:48

Protocols are "global" so, no. You'd need to modify the protocol to not convert the specific column.

👍 1
hanDerPeder20:03:22

So without this guy, next.jdbc would return what? string? bytearray?

hanDerPeder20:03:55

probably PGobject facepalm

seancorfield20:03:08

Yup, plain ol' PGObject...

seancorfield20:03:35

I guess it depends on what you mean by "jsonb column that I want to return directly to clients"...?

seancorfield20:03:08

You may be able to CAST() it to something in SQL that avoided the PGObject decoding, but returns something useful?

💯 1
hanDerPeder20:03:30

it's geojson, all nicely laid out for a maplib to consume in the browser.

hanDerPeder20:03:23

I'll try casting it to bytes, thanks.

isak20:03:33

Yea you could probably cast it to a string that is json

seancorfield20:03:51

So instead of PGObject or Clojure data, it sounds like you want regular JSON as a string?

hanDerPeder20:03:42

yes, ideally a bytestream I can return as the response body

seancorfield20:03:17

So, right now, you get a Clojure data structure and you have to convert that "back" to JSON for the response?

hanDerPeder20:03:34

["select geojson::text from t limit 1"]
thanks guys 👍

👍 1
1