This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-30
Channels
- # announcements (31)
- # aws (17)
- # babashka (26)
- # babashka-sci-dev (8)
- # beginners (16)
- # biff (1)
- # calva (9)
- # cider (5)
- # clj-kondo (3)
- # clj-on-windows (38)
- # cljdoc (2)
- # cljs-dev (9)
- # cljsrn (6)
- # clojure (58)
- # clojure-europe (47)
- # clojure-nl (3)
- # clojure-norway (21)
- # clojure-uk (2)
- # clojurescript (25)
- # conjure (2)
- # data-science (7)
- # datomic (3)
- # emacs (12)
- # events (5)
- # fulcro (5)
- # honeysql (10)
- # introduce-yourself (7)
- # lsp (4)
- # meander (3)
- # nbb (18)
- # off-topic (28)
- # rdf (1)
- # releases (2)
- # sci (5)
- # shadow-cljs (23)
- # sql (5)
- # test-check (3)
New day, new question. I would love to be able to create a temporary table, but there doesn’t seem to be a hh/create-tmp-table
(or underlying support for {:create-tmp-table ...}
?
I ended up with (at least for now)
(honey.sql/register-clause! :create-temp-table (fn [_ args]
[(str "CREATE TEMP TABLE " (name args) " AS")])
:select)
Next question: I want to duplicate some rows in a table while changing one column. I don’t want to enumerate all the columns, so I’ve come up with this:
CREATE TEMP TABLE tmp AS (select * from foo where lol = 42);
UPDATE tmp SET lol = 43;
INSERT INTO foo (SELECT * from tmp);
DROP TABLE tmp;
(I’d be happy to get recommendations for better solutions)
So these seem to be four separate sql statements, which means I need to call honey/format
on a vector containing these, as my honey atm looks like:
(let [tmp-table (gensym)]
[(-> {:create-temp-table (keyword tmp-table)}
(hh/select :*)
(hh/from (keyword "foo")
(hh/where [:= :lol 42))
(-> (hh/update (keyword tmp-table))
(hh/set {:lol 43}))
(-> (hh/insert-into [(keyword "foo")
(-> (hh/select :*)
(hh/from (keyword tmp-table)))]))
(hh/drop-table tmp-table)]))
And then, somewhere else, I’d need:
(map honey/format xs)
Is this the approach or am I missing somehting?Oh, my colleague was smarter than me:
(hh/create-table-as :temp (keyword tmp-table))
gives me a temp table 🙂
Yeah, I should probably call that out in the docs that all the :create*
operations accept one or more keywords and just make SQL out of them 🙂
user=> (sql/format (-> (create-table-as :fee :fie :foe :fum) (select :*) (from :bar)))
["CREATE FEE FIE FOE TABLE fum AS SELECT * FROM bar"]
user=>
And, just in case you weren't aware, I'm really appreciative of the work you do with next.jdbc and honey. They're such a pleasure to work with!

Thank you! It's always nice to hear that. As you well know, as a project maintainer, all you tend to see is a steady stream of complaints about documentation and bugs and questions that are often answered by RTFM 🙂