# Not possible to pass more then one vector variable to or-join

**URL:** <https://forum.datomic.com/t/not-possible-to-pass-more-then-one-vector-variable-to-or-join/1591>\
**Category:** Datomic Pro\
**Created:** [August 20, 2020, 9:45pm UTC](https://forum.datomic.com/t/not-possible-to-pass-more-then-one-vector-variable-to-or-join/1591 "2020-08-20T21:45:26Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikolayandr](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/nikolayandr/32/375_2.png) [@nikolayandr](https://forum.datomic.com/u/nikolayandr)\
**Post date:** [August 20, 2020, 9:45pm UTC](https://forum.datomic.com/t/not-possible-to-pass-more-then-one-vector-variable-to-or-join/1591/1 "2020-08-20T21:45:26Z")

</div>

The example schema:

```
(def schema
[
        {
          :db/ident :type
          :db/valueType :db.type/string
          :db/cardinality :db.cardinality/one
        }
        {
          :db/ident :typeCode
          :db/valueType :db.type/long
          :db/cardinality :db.cardinality/one
        }
        {
          :db/ident :typeId
          :db/valueType :db.type/long
          :db/cardinality :db.cardinality/one
        }
])

(d/transact conn schema)

```

Example data:

```
(def data [
  {
    :type "User"
    :typeCode 1
    :typeId 1
  }
  {
    :type "User"
    :typeCode 2
    :typeId 2
  }
])
(d/transact conn data)

```

The next query fails:

```
(d/q "[ 
:find ?e 
:in $ ?type [?typeIds ...] [?typeCodes ...] 
:where 
  [?e :type ?type]
  (or-join [?e ?typeCodes ?typeIds]
    [?e :typeCode ?typeCodes]
    [?e :typeId ?typeIds]
  )
]"
(d/db conn), "User" [1, 2], [1, 2])

```

then the next error happens:

> Execution error (ArrayIndexOutOfBoundsException) at datomic.datalog/fn$project (datalog.clj:503).  
> Index 2 out of bounds for length 2

if to pass non vector variables:

```
(d/q "[ 
:find ?e 
:in $ ?type ?typeIds ?typeCodes
:where 
  [?e :type ?type]
  (or-join [?e ?typeIds ?typeCodes]
    [?e :typeCode ?typeCodes]
    [?e :typeId ?typeIds] 
  )
]"
(d/db conn), "User" 1, 1)

```

then all works.

P.S.

1. Do not try to understand the any meaning in the schema and queries, it is just the quickest example to show the problem
2. All failed queries are executed successfully when DB is empty
3. Looks like the order of vector variables from **:in** section matters for the order of variables for **rule-vars** of **or-join**

if to execute

```
(d/q "[ 
:find ?e 
:in $ ?type [?typeCodes ...] [?typeIds ...] 
:where 
  [?e :type ?type]
  (or-join [?e ?typeCodes ?typeIds]
    [?e :typeCode ?typeCodes]
    [?e :typeId ?typeIds] 
    [(get-else $ ?e :typeId ?typeIds) ?someIds]
    [(get-else $ ?e :typeCode ?typeCodes) ?someCodes]
  )
]"
(d/db conn), "User" [1, 2], [1, 2])

```

when **?typeIds** is the last listed in **:in** section and **rule-vars** then the next error happens:

> :db.error/insufficient-binding [?typeIds] not bound in expression clause: [(get-else $ ?e :typeId ?typeIds) ?someIds]

datomic-on-prem:1.0.6202

---

<div class="post-metadata">

**Author:** ![nikolayandr](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/nikolayandr/32/375_2.png) [@nikolayandr](https://forum.datomic.com/u/nikolayandr)\
**Post date:** [August 20, 2020, 9:54pm UTC](https://forum.datomic.com/t/not-possible-to-pass-more-then-one-vector-variable-to-or-join/1591/2 "2020-08-20T21:54:18Z")

</div>

@marshall @stu @jaret Guys, can it somehow related to

> [@Not possible to pass attributes as argument for fulltext used inside or-join](https://forum.datomic.com/t/not-possible-to-pass-attributes-as-argument-for-fulltext-used-inside-or-join/1357):
>
> Hi, query execution fails when I’m trying to execute the next datalog query: (d/q "[:find ?user :in $ [?userNameAttrs1 ...] [?userNameAttrs2 ...] ?userNameValue1 ?userNameValue2 :where (or-join [?user ?userNameAttrs1 ?userNameAttrs2 ?userNameValue1 ?userNameValue2] [(fulltext $ ?userNameAttrs1 ?userNameValue1) [[?user \_ \_ \_]]] [(fulltext $ ?userNameAttrs2 ?userNameValue2) [[?user \_ \_ \_]]] ) ]" (d/db conn), [:user/name.EN :user/name.ES] [:user/name.EN :user/name.ES] "Bob\*" "Tob\*" ) Err…

and

> [@Order of variables matters when attributes are passed as arguments](https://forum.datomic.com/t/order-of-variables-matters-when-attributes-are-passed-as-arguments/1345/3):
>
> I made an adjustment and was able to reproduce the behavior you’re seeing. We will investigate.

?

---

<div class="post-metadata">

**Author:** ![jaret](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/jaret/32/45_2.png) [@jaret](https://forum.datomic.com/u/jaret)\
**Post date:** [August 21, 2020, 2:28pm UTC](https://forum.datomic.com/t/not-possible-to-pass-more-then-one-vector-variable-to-or-join/1591/3 "2020-08-21T14:28:30Z")

</div>

Hi @nikolayandr,

Regarding the general case of supplying two vectors to an `or-join`. I’ve reproduced the behavior and we are investigating for a resolution. We will update this thread and your case once we have more information. Thank you for the report!

> [@nikolayandr](#):
>
> ```auto
> (d/q "[ 
> :find ?e 
> :in $ ?type [?typeCodes ...] [?typeIds ...] 
> :where 
> [?e :type ?type]
> (or-join [?e ?typeCodes ?typeIds]
> [?e :typeCode ?typeCodes]
> [?e :typeId ?typeIds] 
> [(get-else $ ?e :typeId ?typeIds) ?someIds]
> [(get-else $ ?e :typeCode ?typeCodes) ?someCodes]
> )
> ]"
> (d/db conn), "User" [1, 2], [1, 2])
> 
> ```

`Or-joins` require that all inputs be bound. The get-else in this scenario is not binding one side of the `or-join`. Thus one side is unbound. I wanted to clarify that because even after we address the multiple vectors this approach would not work.

Thanks,  
Jaret

---

<div class="post-metadata">

**Author:** ![nikolayandr](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/nikolayandr/32/375_2.png) [@nikolayandr](https://forum.datomic.com/u/nikolayandr)\
**Post date:** [August 27, 2020, 10:45am UTC](https://forum.datomic.com/t/not-possible-to-pass-more-then-one-vector-variable-to-or-join/1591/4 "2020-08-27T10:45:12Z")

</div>

Thank you, @jaret . I believe [Not possible to pass attributes as argument for fulltext used inside or-join](https://forum.datomic.com/t/not-possible-to-pass-attributes-as-argument-for-fulltext-used-inside-or-join/1357) also relates to this issue. Could you please let know whether it is the same issue, so that we could plan our future work, thanks.

---

<div class="post-metadata">

**Author:** ![xlfe](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/xlfe/32/509_2.png) [@xlfe](https://forum.datomic.com/u/xlfe)\
**Post date:** [July 16, 2021, 10:06am UTC](https://forum.datomic.com/t/not-possible-to-pass-more-then-one-vector-variable-to-or-join/1591/5 "2021-07-16T10:06:58Z")

</div>

Hi @jaret / @nikolayandr just wondering if this question/bug was ever resolved? I think I’ve hit it. Easy work around for my use case, but curious non-the-less.

Thanks  
Felix

---

<div class="post-metadata">

**Author:** ![jaret](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/jaret/32/45_2.png) [@jaret](https://forum.datomic.com/u/jaret)\
**Post date:** [July 16, 2021, 5:46pm UTC](https://forum.datomic.com/t/not-possible-to-pass-more-then-one-vector-variable-to-or-join/1591/6 "2021-07-16T17:46:03Z")

</div>

Hi @xlfe Thanks for checking in. We are targeting this fix for our next release, but we are currently working through items for that release. I cannot promise that any particular fix/feature will make the release, but the current plan is to work to incorporate this fix.

---

<div class="post-metadata">

**Author:** ![xlfe](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/xlfe/32/509_2.png) [@xlfe](https://forum.datomic.com/u/xlfe)\
**Post date:** [July 18, 2021, 1:04pm UTC](https://forum.datomic.com/t/not-possible-to-pass-more-then-one-vector-variable-to-or-join/1591/7 "2021-07-18T13:04:45Z")

</div>

Thanks - sounds like its in the works which is great.

---

<div class="post-metadata">

**Author:** ![mperrotta](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mperrotta](https://forum.datomic.com/u/mperrotta)\
**Post date:** [October 19, 2022, 3:33pm UTC](https://forum.datomic.com/t/not-possible-to-pass-more-then-one-vector-variable-to-or-join/1591/8 "2022-10-19T15:33:06Z")

</div>

Any update on this? I’m seeing the same problem in datomic-cloud

---

<div class="post-metadata">

**Author:** ![nikolayandr](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/nikolayandr/32/375_2.png) [@nikolayandr](https://forum.datomic.com/u/nikolayandr)\
**Post date:** [January 31, 2023, 1:00pm UTC](https://forum.datomic.com/t/not-possible-to-pass-more-then-one-vector-variable-to-or-join/1591/9 "2023-01-31T13:00:52Z")

</div>

I see `datomic-1-0-6610` still contains this issue, not sure but looks like [Does not-join support working with collection variables?](https://forum.datomic.com/t/does-not-join-support-working-with-collection-variables/2177) might be related to this issue

---

<div class="post-metadata">

**Author:** ![nikolayandr](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/nikolayandr/32/375_2.png) [@nikolayandr](https://forum.datomic.com/u/nikolayandr)\
**Post date:** [January 31, 2023, 1:04pm UTC](https://forum.datomic.com/t/not-possible-to-pass-more-then-one-vector-variable-to-or-join/1591/10 "2023-01-31T13:04:02Z")

</div>

Hi @jaret. Could you please tell me whether is there any updates on this issue?

---

<div class="post-metadata">

**Author:** ![nikolayandr](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/nikolayandr/32/375_2.png) [@nikolayandr](https://forum.datomic.com/u/nikolayandr)\
**Post date:** [March 27, 2023, 5:36pm UTC](https://forum.datomic.com/t/not-possible-to-pass-more-then-one-vector-variable-to-or-join/1591/11 "2023-03-27T17:36:20Z")

</div>

@jaret please tell us about any plans to release the fix for this issue

---

<div class="post-metadata">

**Author:** ![nikolayandr](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/nikolayandr/32/375_2.png) [@nikolayandr](https://forum.datomic.com/u/nikolayandr)\
**Post date:** [December 25, 2023, 5:41pm UTC](https://forum.datomic.com/t/not-possible-to-pass-more-then-one-vector-variable-to-or-join/1591/12 "2023-12-25T17:41:47Z")

</div>

@jaret is there any chance to get a fix for this issue?

---

<div class="post-metadata">

**Author:** ![Gallant](https://avatars.discourse-cdn.com/v4/letter/g/6bbea6/32.png) [@Gallant](https://forum.datomic.com/u/Gallant)\
**Post date:** [December 27, 2023, 1:03pm UTC](https://forum.datomic.com/t/not-possible-to-pass-more-then-one-vector-variable-to-or-join/1591/13 "2023-12-27T13:03:36Z")

</div>

Any updates on this issue?

---

<div class="post-metadata">

**Author:** ![nikolayandr](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/nikolayandr/32/375_2.png) [@nikolayandr](https://forum.datomic.com/u/nikolayandr)\
**Post date:** [September 1, 2025, 1:31pm UTC](https://forum.datomic.com/t/not-possible-to-pass-more-then-one-vector-variable-to-or-join/1591/15 "2025-09-01T13:31:09Z")

</div>

Hi, could you please share your workaround?

@jaret Could you please tell whether there are any updates since 2021?
