This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-02
Channels
- # adventofcode (6)
- # announcements (6)
- # babashka (21)
- # babashka-sci-dev (18)
- # biff (6)
- # clara (4)
- # clj-commons (2)
- # clj-kondo (7)
- # cljdoc (4)
- # clojure (9)
- # clojure-berlin (8)
- # clojure-europe (23)
- # clojure-gamedev (3)
- # clojure-indonesia (1)
- # clojure-nl (1)
- # clojure-norway (10)
- # clojure-poland (1)
- # clojurescript (27)
- # community-development (1)
- # conjure (32)
- # etaoin (6)
- # events (20)
- # fulcro (5)
- # graalvm (1)
- # helix (19)
- # hyperfiddle (14)
- # introduce-yourself (2)
- # music (1)
- # nbb (24)
- # off-topic (37)
- # pathom (2)
- # polylith (14)
- # reagent (11)
- # releases (1)
- # remote-jobs (1)
- # reveal (22)
- # shadow-cljs (16)
- # sql (3)
- # squint (11)
- # test-check (2)
- # xtdb (36)
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?
thanksTo 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.
Thanks! I ll go with 'query' then