FAQ
Hi,

You probably need to realize your query using (doall (jdbc/query ...))

Also, I was wondering, depending on your needs, you could convert
Jdbc4Arrayinto a native type (vector ?) as a post-processing function
of your query
and forget about registering JSON writers.


On Tue, Oct 1, 2013 at 9:00 PM, Christian Jauvin wrote:

Hi Roman,

This approach works for java.sql.Timestamp, which was another type for
which a JSON writer wasn't defined in my case.

For org.postgresql.jdbc4.Jdbc4Array however, there's something missing,
because I get:

*org.postgresql.util.PSQLException: This connection has been closed.*

As the person answering me on Stack Overflow suggested, it seems that the
resultset should be somehow processed before the connection is closed, but
I really don't know how to do given the construct I'm currently using:

(json/write-str
(jdbc/query *db*
["SELECT * FROM .."]))

where and how could I intercept the resultset that way? Thanks.


On Tuesday, October 1, 2013 12:49:10 PM UTC-4, r0man wrote:

I think you need to implement the JSONWriter protocol for the
Jdbc4Array class, and possibly for the datatypes that are in the
array. This for example makes the json library aware of
java.util.Date classes.

(extend-type java.util.Date
JSONWriter
(-write [date out]
(-write (str date) out)))

Something like this (not tested):

(extend-type org.postgresql.jdbc4.**Jdbc4Array
JSONWriter
(-write [array out]
(-write (seq (.getArray array)) out)))

Roman

On Tuesday, October 1, 2013 3:57:02 PM UTC+2, Christian Jauvin wrote:

Hi,

I asked this question on Stack Overflow yesterday:

I want to jsonify the results of a query performed against a Postgres
table containing a column of type text[], but the problem is that
clojure.data.json.write-str doesn't seem to know how to handle PG
arrays:

*Exception Don't know how to write JSON of class org.postgresql.jdbc4.Jdbc4Array
clojure.data.json/write-generic*

Do I have to supply a custom handler, or is there a simpler way?


http://stackoverflow.com/**questions/19103870/jsonify-a-**
jdbc4array-in-clojure<http://stackoverflow.com/questions/19103870/jsonify-a-jdbc4array-in-clojure>

I'm asking it here in the hope of getting (maybe) a simpler solution, or
at least one I can implement readily, because the problem I have with one
of the suggestions I received (extending org.postgresql.jdbc4.**
Jdbc4Array to implement the missing function) is that I don't know how
to make it work with my usage pattern, which is simply:

(json/write-str
(jdbc/query *db*
["SELECT * FROM ..."]))

How do I "get the array before the connection is closed" with such a
construct? Is there another way?

--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with
your first post.
To unsubscribe from this group, send email to
clojure+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to clojure+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


--
Philippe

--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 4 of 9 | next ›
Discussion Overview
groupclojure @
categoriesclojure
postedOct 1, '13 at 2:12p
activeOct 2, '13 at 2:22p
posts9
users4
websiteclojure.org
irc#clojure

People

Translate

site design / logo © 2021 Grokbase