Skip to content

Instantly share code, notes, and snippets.

@ustun
Last active June 27, 2017 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ustun/93f61be83a138533e0e91249020e57a7 to your computer and use it in GitHub Desktop.
Save ustun/93f61be83a138533e0e91249020e57a7 to your computer and use it in GitHub Desktop.
Postgresql citext support with Clojure JDBC + Postgres
;; 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%2BzHoiwLz-EG7W2a4A@mail.gmail.com
@dotemacs
Copy link

Thank you for gisting this!

The suffix: ?stringtype=unspecified was a timesaver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment