xtdb

esp1 2024-10-24T08:30:24.042899Z

In xtdb 1/datomic you can query reverse relationships by prepending an underscore to an attribute name. Is this kind of reverse relationship query possible in XTQL?

jarohen 2024-10-24T09:08:59.546819Z

have you got a pseudo-code example of what you're trying to do?

jarohen 2024-10-24T09:09:35.534389Z

(my initial thought is that this should be a slight adaptation in the call to nest-one/nest-many)

esp1 2024-10-28T23:19:42.106109Z

I answered my own question with this - unify does what I need

jarohen 2024-10-29T09:28:38.027659Z

🙌 if possible, mind sharing it here in case others run into the same problem?

esp1 2024-10-29T16:25:24.040839Z

It turns out I didn't actually need the reverse relationship query for my use case, I was able to do what I needed with normal forward queries. I am storing dependency information in xtdb, and I wanted to ask questions like 'what entities are dependent on entity X, and via what relation?' In order to do that I was originally thinking that I would somehow walk backward from entity X through relationships, but afterwards I realized that I would not only need reverse relationships, but also to somehow ask which reverse relationships refer to entity X, which I don't think is something I can do in a query. After thinking this through more, I wound up essentially querying my dependency graph for things that refer to X, and then things that refer to those things, etc. - which I was able to do because I had stored enough meta information in my graph to know what the possible forward relationships were.

tatut 2024-10-24T13:52:15.605169Z

just came to mind, that in normal SQL, trying to insert with the same PK will fail due to primary key constraint (unless you provide some upsert clauses)… in XTDBv2 it succeeds with a new version.

tatut 2024-10-24T13:52:37.783819Z

I’m not saying that it’s a problem, just though of it that it is a marked difference

tatut 2024-10-25T04:50:50.234549Z

is there a way to “upsert”, the SQL syntax graph doesn’t show way to say that “if it exists, then (merge old new)”