Fork me on GitHub
#xtdb
<
2022-09-03
>
twashing22:09:44

This is taken from the bottom of XTDB tx/match tutorial. • https://nextjournal.com/xtdb-tutorial/match Why does the query below only return the single item in the list, and not return the entire list? The behaviour doesn’t seem to match any of XTDB Datalog’s :in type. • https://docs.xtdb.com/language-reference/datalog-queries/#in

(xt/submit-tx
 node
 [[::xt/put
   {:xt/id :manifest
    :pilot-name "Johanna"
    :id/rocket "SB002-sol"
    :id/employee "22910x2"
    :badges ["SETUP" "PUT" "DATALOG-QUERIES" "BITEMP" "MATCH"]
    :cargo ["stereo" "gold fish" "slippers" "secret note"]}]])

(xt/sync node)

(xt/q (xt/db node)
    '{:find [belongings]
      :where [[e :cargo belongings]]
      :in [belongings]}
    "secret note")

;; Returns... #{["secret note"]}) ... not #{["stereo" "gold fish" "slippers" "secret note"]}

twashing22:09:42

Or said another way 👆:skin-tone-5: What would be the query for… “i. Find the entity, ii. whose vector attribute contains X… and return the entire vector?

walterl22:09:23

Interesting question! This works for me:

(xt/q (xt/db node)
      '{:find [c]
        :where [[e :cargo belongings]
                [e :cargo c]]
        :in [belongings]}
      "secret note") ; #{["slippers"] ["secret note"] ["gold fish"] ["stereo"]}

walterl22:09:37

Or

(xt/q (xt/db node)
      '{:find [(pull e [:cargo])]
        :where [[e :cargo belongings]]
        :in [belongings]}
      "secret note") ; #{[{:cargo ["stereo" "gold fish" "slippers" "secret note"]}]}

walterl22:09:54

But the latter wraps it in an extra {:cargo ...}, though

twashing22:09:44

@UJY23QLS1 Ooooh I get it. In my original query, :find returns the belongings comparator / binding I submitted. But you created a separate c binding that is the actual vector. Got it. Cheers mate 👍:skin-tone-5:

👍 1
🙏 1
1