# Constrained Recursion with datalog

**URL:** <https://forum.datomic.com/t/constrained-recursion-with-datalog/1513>\
**Category:** Datomic Cloud\
**Created:** [July 4, 2020, 10:20pm UTC](https://forum.datomic.com/t/constrained-recursion-with-datalog/1513 "2020-07-04T22:20:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pablo](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@pablo](https://forum.datomic.com/u/pablo)\
**Post date:** [July 4, 2020, 10:20pm UTC](https://forum.datomic.com/t/constrained-recursion-with-datalog/1513/1 "2020-07-04T22:20:18Z")

</div>

I am trying to use recursion with the pull syntax but limit the recursion. I have the following query and I am trying to limit the children but to no avail.

```
(d/q '[:find (pull ?e pattern)
       :in $ pattern ?foo-id
       :where
       [?f :foo/id ?foo-id]
       [?f :foo/children ?c]
       [?c :child/label "Chosen one"]]
  db '[* {:foo/children ...}] foo-id))

```

I realize that the pull syntax which allows the recursion is just for pulling information, but how would I do recursion that limits the children in this case?

---

<div class="post-metadata">

**Author:** ![souenzzo](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/souenzzo/32/57_2.png) [@souenzzo](https://forum.datomic.com/u/souenzzo)\
**Post date:** [July 8, 2020, 7:20pm UTC](https://forum.datomic.com/t/constrained-recursion-with-datalog/1513/2 "2020-07-08T19:20:07Z")

</div>

“pull select syntax” describes that `[{:foo ...}]` is "infinite recursion but you can specify `[{:foo 3}]` to limite the recursion to 3 levels
