I understand how to:
- Query JSON in Postgres
- How to query JSON data from postgresql in sqlalchemy
- how to use clojure.java.jdbc
But I don't know how to put it together and query json with clojure.java.jdbc.
For example, I have a table user, and a field user_info
CREATE TABLE user (id SERIAL,user_info JSON);
then I found this blog to impl some protocol,and it insert success!
(insert! conn :yxt_user {:user_info {:hello [1 "test" true]}})
But I don't know how to write code to query it like this sql from jdbc/query
SELECT * FROM user WHERE data ? 'hello';
not by jdbc/execute direct write sql like
(jdbc/execute! db-spec ["UPDATE table SET col1 = NOW() WHERE id = ?" 77])
I tried to write this query
(jdbc/query conn ["SELECT * FROM user WHERE user_info ? 'hello'"])
I got this
org.postgresql.util.PSQLException: 未设定参数值 1 的内容。
Then I tried
(jdbc/query conn ["SELECT * FROM user WHERE user_info ? 'hello'" "?"])
I got this
org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"
How do I write a query to filter on a JSON column where user_info has the JSON key hello
?