Last active
June 27, 2017 16:39
-
-
Save ustun/93f61be83a138533e0e91249020e57a7 to your computer and use it in GitHub Desktop.
Postgresql citext support with Clojure JDBC + Postgres
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; citext with JDBC | |
;; Using the technique at: http://hiim.tv/clojure/2014/05/15/clojure-postgres-json/ | |
(import 'org.postgresql.util.PGobject) | |
(extend-protocol j/IResultSetReadColumn | |
PGobject | |
(result-set-read-column [pgobj metadata idx] | |
(let [type (.getType pgobj) | |
value (.getValue pgobj)] | |
(case type | |
"citext" (.toString value) | |
:else value)))) | |
;; For queries, you need to prevent jdbc from coercing to string | |
;; add the following to the jdbc uri | |
;; ?stringtype=unspecified | |
;; Source: https://www.postgresql.org/message-id/CAJFs0QC_nn5WxhrgMuXsK%3DWCc5JHvMmGk%[email protected] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for gisting this!
The suffix:
?stringtype=unspecified
was a timesaver.