xtdb

esp1 2025-01-06T19:37:05.945339Z

Is there a way to query for which entities/attributes refer to a particular value in xtdb? In datomic I can do something like this to find the entities and attributes that refer to :some/id :

(d/q '[:find ?entity ?attr-ident
       :where [?entity ?attr :some/id]
              [?attr :db/ident ?attr-ident]
     db)
I'm wondering if this kind of thing is possible in xtdb?

jarohen 2025-01-06T21:39:47.613839Z

hey @esp1, afraid not, this isn't an index we keep - we expect the attributes to be statically known

esp1 2025-01-06T21:57:57.076369Z

ok, thanks for the info -

refset 2025-01-06T23:07:41.965359Z

well, in v1 you can do this https://gist.github.com/refset/93135adcbf41fccab9b641638ab10997 and in v2 you can do something similar using the information_schema tables, but it inevitably requires two queries (same as most SQL databases, without dropping down to some procedural dialect)

esp1 2025-01-07T22:14:13.016479Z

Thanks @taylor.jeremydavid - if I understand this correctly, first you query for all known attributes, and then query for any relation where one of these attributes has the target value?

refset 2025-01-07T23:36:36.940929Z

yep that's right 🙂