标题说明了一切,但说我有一个简单的查询,如下所示:
(q '[:find ?c ?n :where [?c :my-thing/its-attribute ?n]]
(d/db conn))
针对像这样的模式
[{:db/id (d/tempid :db.part/db)
:db/ident :my-thing/its-attribute
:db/valueType :db.type/string
:db/doc "My thing's attribute"
:db/cardinality :db.cardinality/one
:db.install/_attribute :db.part/db}]
如果查询匹配所有内容(例如100M个条目),则返回的结果将很大。如果我只想要其中的几个,什么是最好的方法?
最佳答案
使用rand(允许重复)和sample(仅不同)的两个随机名称
(d/q '[:find [(rand 2 ?name) (sample 2 ?name)]
:where [_ :artist/name ?name]]
db)
这个例子来自day-of-datomic github repo。
关于clojure - Datomic中的SQL "limit"子句的等效项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27162566/