Fork me on GitHub
#sql
<
2018-02-24
>
xlevus10:02:38

I'm playing with some jsonb fields in postgres, and I can execute my query against my schema fine using the postgres cli

SELECT * FROM document WHERE _type = 'debug' AND _data -> 'a' = '1';
+-------+---------+----------+
| _id   | _type   | _data    |
|-------+---------+----------|
| 2     | debug   | {"a": 1} |
+-------+---------+----------+
Yet, when executing the same (I assume?) query through jdbc, I get an error about field types. My equivalent query-vector
["SELECT * FROM document WHERE _type = ? AND _data -> ? = ?" "test" "a" "1"]
with the error
postgres_1  | ERROR:  operator does not exist: jsonb = character varying at character 57
postgres_1  | HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
postgres_1  | STATEMENT:  SELECT * FROM document WHERE _type = $1 AND _data -> $2 = $3

xlevus10:02:23

jdbc is making 1 a character, not a string

rymndhng21:02:33

I wrote a post on using clojure.java.jdbc with postgres and cursors! https://rymndhng.github.io/blog/2018/02/24/clojure-jdbc-resultset-cursors/

xlevus22:02:50

is it possible to add a literal ? symbol into a query with jdbc?

xlevus22:02:36

yes: ?? works