honeysql

bteuber 2024-07-09T08:13:56.571939Z

Hi! I'm trying to insert data into a postgres table with a jsonb column like this:

(sql/run! (-> (h/insert-into :my_table)
              (h/values [{:user_id 1
                          :my_jsonb_col [:lift {:title "Epic Battle"}]}])))
However, when running it, I get an error about no hstore extension installed. Do I manually need to convert it to json, different from what https://github.com/seancorfield/honeysql/blob/develop/doc/postgresql.md#jsonjsonb states?

p-himik 2024-07-09T08:29:26.296779Z

HoneySQL just creates SQL queries. It doesn't attempt to understand the underlying DB types - that's the job for JDBC. In this case, a relevant section would be https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.3.939/doc/getting-started/tips-tricks?q=json#working-with-json-and-jsonb

igrishaev 2024-07-09T08:55:19.847179Z

This is because by default, PG JDBC encodes java.util.Map instances into the hstore type, which is a map of String->String. Please refer to the link shared above and extend protocols with PersistentMap/PGObject types

bteuber 2024-07-09T10:04:39.745129Z

Ah, thanks! I somehow assumed honey does the conversion, too..