This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-06-08
Channels
- # babashka (9)
- # beginners (43)
- # biff (4)
- # calva (11)
- # cider (6)
- # clerk (1)
- # clj-kondo (4)
- # cljs-dev (6)
- # clojure (82)
- # clojure-berlin (1)
- # clojure-europe (42)
- # clojure-nl (1)
- # clojure-norway (182)
- # clojure-quebec (1)
- # clojure-uk (19)
- # clojurescript (6)
- # datahike (1)
- # emacs (30)
- # fulcro (5)
- # honeysql (6)
- # hyperfiddle (12)
- # lambdaisland (8)
- # malli (11)
- # off-topic (36)
- # pathom (26)
- # pedestal (1)
- # portal (25)
- # practicalli (1)
- # rdf (29)
- # re-frame (17)
- # reitit (1)
- # releases (1)
- # sci (37)
- # shadow-cljs (15)
- # vim (10)
- # xtdb (13)
I'm trying to build a query with CTE that carries VALUES:
with vals (a, b) as (
values (1, 2),
(3, 4)
)
select table.*
from table join vals on ...
here is what I've got in my code:
{:with
[
[[:vals {:columns [:foo :bar]}]
{:values [{:foo 1 :bar 2} {:foo 1 :bar 2}]}]
]
:select [:*]
:from [:events]
:join
[:vals [:= :foo.bar :events.test]]
}
which gives
"WITH vals (foo, bar) AS ((foo, bar) VALUES (?, ?), (?, ?))
SELECT * FROM events...
the problem is, I cannot get rid from the second (foo, bar)
in front of VALUES. How can I do this?There is an example in the docs:
You can use a VALUES clause in the CTE:
user=> (sql/format {:with [[[:stuff {:columns [:id :name]}]
{:values [[1 "Sean"] [2 "Jay"]]}]]
:select [:id :name]
:from [:stuff]})
["WITH stuff (id, name) AS (VALUES (?, ?), (?, ?)) SELECT id, name FROM stuff" 1 "Sean" 2 "Jay"]
from https://cljdoc.org/d/com.github.seancorfield/honeysql/2.4.1033/doc/getting-started/sql-clause-reference#with-with-recursiveNP. Your Q made me wonder if I'd omitted that from the docs, so I needed to check. I guess it could also state explicitly that you can't use the vector-of-maps version of :values
...