How to write one datomic query, taking into account the whole set

Is it possible to write such queries in datomic?

  • find the name of the oldest child
  • find the person with the lowest body mass index (weight / height)
+6
source share
1 answer
[:find (max ?tuple) :where [?k :kid/age ?age] [?k :kid/name ?name] [(vector ?age ?name) ?tuple] 

Note:

  • the order of the attributes in the expression (vector ?age ?name) matters

  • the query returns one result, while we can expect a collection, because there can be many children in the age who are maximum in the set. You can use (max n ?tuple) to achieve this.

See also the Returning Aggregates section at http://docs.datomic.com/query.html

If you have something more specific, provide more details in the question and include your circuit.

+7
source

All Articles