Search code examples
datomicdatalog

Subquery support in datomic


Does datomic support subqueries or can those be simulated within a query? That would essentially be a :find within another :find.

I'm trying to perform analytical transformations of data in the query/DB itself rather than in the application.


Solution

  • Yes, you can issue a 'subquery' in Datomic. An example is provided here.

    It's also worth noting that because the work of query happens in your peer (assuming you're using the Peer API), there is not the same "n+1 problem" penalty for issuing two separate queries as you would have with a traditional RDB. So in addition to the sub-query approach, you could also issue the 'inner' query first, then pass the results from it as parameters to the 'outer' query.

    -Marshall