Fork me on GitHub
#xtdb
<
2022-07-21
>
Ivan Koz12:07:27

Hi i need to query an attribute of the document on two different valid-times and output it at once any examples of such a query?

jarohen12:07:29

hey @UH16CGZC2 👋 XT only does single-point-in-time queries, so I'd recommend making two queries at the two different valid-times and combining them in your application

refset12:07:32

You can embed other history calls and queries inside a top-level query, if that might be of use: https://gist.github.com/refset/8439ceebf3c1f08c614b0c818266a140

🙏 1
Ivan Koz12:07:38

oh alright, and i choose target valid time when acquiring db instance right?

👍 1
Ivan Koz14:07:44

Look at that monster, any way to simplify it? Maybe by pull syntax or something.

refset15:07:42

It looks like you could cut out 3 of the clauses using pull, yep: :find [(pull ?clan [:clan/name]) (pull ?profile [:profile/name :profile/rank]) ?cbw-old ?cbw ?cbw-diff]

refset15:07:43

a differently shaped monster, perhaps 🙂

refset15:07:16

I guess the more Datalog you write the more you get used to it, and the simpler it ends up looking...

Ivan Koz15:07:13

sure, it works for everything 😃

Ivan Koz16:07:41

is it possible to add something else to a join when building nested results using pull, like ?cid

(q '{:find [(pull ?clan [:clan/name {:clan/members [:profile/name [?cid :as :cid]]}])]
     :where [[?clan :clan/name "..."]
             [?clan :xt/id ?cid]]})

expected output
#{[{:clan/name    "..."
    :clan/members [{:profile/name "..."
                    :cid          "..."}
                   {...}]}]}

refset17:07:50

sadly not, you can't mix pull and regular clauses like that. The pull always happens as the ~last step in the query execution

refset17:07:36

You could possible wrap the result of a pull in an outer-query, then use get-in again...but I'm not sure that's ultimately simpler 😅