Hello I'm a bit unsure of how to do recursive datalog queries and am not too sure where to start
I have a query that goes something like this
{:find [?dataset ?group]
:where [[?dataset :id "..."]
[?dataset :group ?group]]}My data is such that each group may have a parent group indicated by the attribute :parent
how might i go about finding all groups that the dataset is a group of?
Hey π looking at the example(s) in the docs for inspiration https://docs.xtdb.com/language-reference/datalog-queries/#_bound_arguments ...I'd try something similar:
{:find [?dataset ?group ?parent]
:where [[?dataset :xt/id "..."]
[?dataset :group ?group]
(group-parents ?group ?parent)]
:rules [[(group-parents [?group] ?parent)
[?group :parent ?parent]]
[(group-parents [?group] ?parent)
[?group :parent ?subparent]
(group-parents ?subparent ?parent)]]}adjusting the language of "parent"/"subparent" would probably make things clearer but hopefully you get the idea π
Thanks for the link π was trying see where it might be in the docs. Will take a look when I get back home and let you know if I have any issues! (:
if you also need to return the "height" of all the nested parents, you can do it like this: https://gist.github.com/refset/57a910e2b746332ec7a0a31886f57cfb
I think I manged to adapt it to my problem π Thanks for your help!
I should definitely set aside some time to read up the docs tho
I am using xtdb (or rather crux atm)