Fork me on GitHub
#sql
<
2022-09-02
>
kirill.salykin10:09:05

Hi I am using clojure.java.jdbc + honeysql v1 I am trying to get back fields from the insertion

(jdbc/execute! tx
                                     (sql/format {:insert-into   :property-details
                                                  :values        property-details
                                                  :on-conflict   [:property-id :source]
                                                  :do-update-set [:type :ownership :living_area :plot_area
                                                                  :luxury :maintenance :services :location
                                                                  :purchase_date :purchase_price]
                                                  :returning [:property-id :id]})
                                     {:return-keys true})
Unfortunately execute! returns only 1 row (adding :multi? true doesnt work, triggering another exception)
(jdbc/query tx
                                     (sql/format {:insert-into   :property-details
                                                  :values        property-details
                                                  :on-conflict   [:property-id :source]
                                                  :do-update-set [:type :ownership :living_area :plot_area
                                                                  :luxury :maintenance :services :location
                                                                  :purchase_date :purchase_price]
                                                  :returning [:property-id :id]})
                                     {:return-keys true})
This way (using query) works, but it feels not good to me to use query for producing side effects Please advice is there a way to make it work with execute!? or maybe I need another helper function? thanks

seancorfield19:09:14

To use :multi? true, you need to reformat the result of HoneySQL's format because the latter assumes you have a vector with <SQL> and then just a plain list of params but the former assumes you have a vector with <SQL> and then groups of params. As you've found, you can use query to get a full ResultSet back. In c.j.j, under the hood execute! and query use different methods in JDBC to get the job done. next.jdbc is much more consistent in that respect.

kirill.salykin06:09:59

Thanks! I ll go with 'query' then