This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-27
Channels
- # beginners (113)
- # calva (39)
- # cider (18)
- # cljs-dev (19)
- # cljsrn (1)
- # clojure (80)
- # clojure-dusseldorf (1)
- # clojure-finland (1)
- # clojure-gamedev (1)
- # clojure-germany (2)
- # clojure-italy (38)
- # clojure-nl (16)
- # clojure-spec (90)
- # clojure-uk (81)
- # clojurescript (28)
- # clojutre (9)
- # cursive (47)
- # data-science (4)
- # datomic (21)
- # emacs (1)
- # events (2)
- # fulcro (11)
- # graphql (2)
- # hoplon (8)
- # hyperfiddle (23)
- # jobs (2)
- # kaocha (4)
- # lein-figwheel (1)
- # luminus (1)
- # mount (1)
- # off-topic (41)
- # pathom (5)
- # pedestal (27)
- # reitit (6)
- # remote-jobs (7)
- # ring-swagger (6)
- # shadow-cljs (42)
- # spacemacs (1)
- # sql (9)
- # tools-deps (6)
- # uncomplicate (2)
- # vim (5)
Hello, I'm strugling with Datalog to express this: give me all the user ids that are not in the list. Here are two versions that I tried and that don't work:
(d/q '[:find [?e ...]
:in $ [?excluded-id ...]
:where
[?e :user/email]
(not-join [?excluded-id]
[?excluded-id :user/email])]
db
[5678 9123])
;; => []
;; no id
(d/q '[:find [?e ...]
:in $ [?excluded-id ...]
:where
[?e :user/email]
[(not= ?e ?excluded-id)]]
db
[5678 9123])
;; => [1234 5678 9123 ...]
;; all the ids
Does someone know how to do that ?
ThanksYou don't want to join against your excluded-id collection. I.e. for any id ?e
, even if it matches one of the excluded ids it can't match all of them. the not-join and not= will only exclude if it doesn't match any of them
'[:find [?e ...]
:in $ ?excluded-id-set
:where
[?e :user/email]
(not [(contains? ?excluded-id-set ?e)])]
(d/q '[:find [?e ...]
:in [?e ...] ?not-e+
:where
(not-join [?e ?not-e+]
[(identity ?not-e+) [?e ...]])
]
[1 2 3 4] [2])
=> [1 3 4]
I will say that using a collection binding [?excluded-id ...]
causes a logical OR to happen.
Logical AND can be enforced by using a double`not-join` as shown here: https://stackoverflow.com/a/43808266
Thanks for the solution. I was almost there with a version that I didn't put:
(d/q '[:find [?e ...]
:in $ ?excluded-ids
:where
[?e :user/email]
[(not (contains? ?excluded-ids ?e))]]
db
(set excluded-ids))
Version that doesn't work either. It doesn't filter and returns all the ids.
Do you know why?Ok thanks. Now I get why my nested version wan't working. Thank you very much @U09R86PA4 and @U424XHTGT
@jaret IMO a solution/example/explaination the above problem statement should be documented somewhere other than slack, as I’ve run into this before and it was extremely difficult to find an answer. Eventually I had to phone a friend from a different corp so he could walk me through it. This was after going through all datomic cloud documentation, all day of datomic cloud, day of datomic documentation, and every post I could find. If I missed something, and then please ignore this documentation request.