Discussion:
Unification with history db
Marc Grue
2017-06-06 19:56:43 UTC
Permalink
Hi,

I have an attribute :ns/str with an initial value "a" that is updated to
"b". So everything is fine when I use a history db to find the assertions
and
retractions over time:

[:find ?v ?op
:where [?e :ns/str ?v _ ?op]]
=>
["a" true]
["a" false]
["b" true]

I'm surprised though that ?v and "a" don't seem to unify in the following
query since I get back the exact same result:

[:find ?v ?op
:where [?e :ns/str ?v _ ?op]
[?e :ns/str "a"]]
=>
["a" true]
["a" false]
["b" true]

Why do I get back "b" also?

Thank you,
Marc
--
You received this message because you are subscribed to the Google Groups "Datomic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to datomic+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Alan Thompson
2017-06-06 20:08:31 UTC
Permalink
You are misunderstanding unification, which happens only on ?e here. Your
query reads "Find any entity ?e that has the attr/val pair of { :ns/str "a"
}. Then, for that ?e, find all values ?v and ops ?o using [?e :ns/str ?v _
?op].

However, if you did this query using the "current" db value after the
update from "a" -> "b" I would not expect it to select the entity in the
first place.

Alan
Post by Marc Grue
Hi,
I have an attribute :ns/str with an initial value "a" that is updated to
"b". So everything is fine when I use a history db to find the assertions
and
[:find ?v ?op
:where [?e :ns/str ?v _ ?op]]
=>
["a" true]
["a" false]
["b" true]
I'm surprised though that ?v and "a" don't seem to unify in the following
[:find ?v ?op
:where [?e :ns/str ?v _ ?op]
[?e :ns/str "a"]]
=>
["a" true]
["a" false]
["b" true]
Why do I get back "b" also?
Thank you,
Marc
--
You received this message because you are subscribed to the Google Groups "Datomic" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Datomic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to datomic+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Marc Grue
2017-06-06 20:36:00 UTC
Permalink
Ah, of course. The same entity has attributes with any number of values
over time in a history db, not just a single ?v (or set).

This gives me what I want:

[:find ?v ?op
:where [?e :ns/str ?v _ ?op]
[(= ?v "a")]]
=>
["a" true]
["a" false]

Thanks,
Marc
--
You received this message because you are subscribed to the Google Groups "Datomic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to datomic+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...