xtdb

esp1 2024-10-28T23:26:59.233159Z

How do I query nested data structures in XTQL? e.g. if I have a structure like:

{:xt/id 1
 :foo {:bar "abc"}}
how would I query for 'objects with attribute :foo that contain :bar = "abc"'?

jarohen 2024-10-29T09:30:04.294539Z

you can access a nested field using Clojure's dot syntax - (. foo bar)

jarohen 2024-10-29T09:31:08.273279Z

so something like

(unify (from :my-table [foo])
       (where (= "abc" (. foo bar))))

1
esp1 2024-10-29T15:21:35.755319Z

Hm, this doesn't seem to work with namespaced fields. If I have a doc

{:xt/id 1 :foo/a {:baz/b "bar"}}
and I try to query it with
(unify (from :docs [xt/id foo/a])
       (where (= (. foo/a baz/b) "bar")))
it returns no results [https://play.xtdb.com/?version=2.0.0-b1&type=xtql&txs=W3sic3lzdGVtLXRpbWUiOm51bGwsInR4cyI6Ils6cHV0LWRvY3MgOmRvY3Mgezp4dC9pZCAxIDpmb28vYSB7OmJhei9iIFwiYmFyXCJ9fV0ifV0%3D&query=KHVuaWZ5IChmcm9tIDpkb2NzIFt4dC9pZCBmb28vYV0pCiAgKHdoZXJlICg9ICguIGZvby9hIGJhei9iKSAiYmFyIikpKQ%3D%3D]

jarohen 2024-10-29T15:24:15.914379Z

thanks @esp1 - that one sounds like a bug 😞 would you be able to raise an issue?

esp1 2024-10-29T16:08:37.680659Z

done: https://github.com/xtdb/xtdb/issues/3826

🙏 1