This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-01-31
Channels
- # aleph (24)
- # announcements (2)
- # aws (1)
- # babashka (2)
- # beginners (46)
- # calva (15)
- # chlorine-clover (1)
- # clojure-europe (27)
- # clojure-nl (3)
- # clojure-norway (13)
- # clojure-uk (7)
- # clojurescript (16)
- # datomic (29)
- # emacs (4)
- # fulcro (16)
- # hugsql (6)
- # hyperfiddle (65)
- # lsp (9)
- # malli (3)
- # off-topic (29)
- # pedestal (1)
- # releases (1)
- # shadow-cljs (52)
- # specter (5)
- # xtdb (1)
How do I translate this to hugsql, where the ids
are a parameter?
WITH inputids (id)
AS (VALUES (109734), (109733), (1111111))
SELECT ib.*
FROM inputids ib
LEFT JOIN foo f
ON ib.id = f.id
WHERE f.id IS NULL
So something like
WITH inputids (id)
AS (VALUES :v*:ids)
SELECT ib.*
FROM inputids ib
LEFT JOIN foo f
ON ib.id = f.id
WHERE f.id IS NULL
But workingI did it using :raw
and
(defn sqlvals [vals]
(string/join "," (map #(format "('%s')" %) vals)))
Not the prettiest but it works!You can use a tuple list parameter type for this: https://www.hugsql.org/hugsql-in-detail/parameter-types/sql-tuple-list-parameters
This:
WITH inputids (id)
AS (VALUES :t*:ids)
SELECT ib.*
FROM inputids ib
LEFT JOIN foo f
ON ib.id = f.id
WHERE f.id IS NULL
gives the error count not supported on this type: Long
:ids
need to take the expected shape of [[3][2][1]]
, since this is a list of tuples.