Realized I'm not sure how to express SELECT * FROM some_table WHERE some_column IN ("foo", "bar") in XTQL. 😅 Any guidance woud be greatly appreciated.
Not sure how to access $vals in this query:
(xt/q node '(-> (from :some_table [*])
...)
{:args {:vals ["foo" "bar"]}}) Relatedly, how does one provide arguments to XTSQL? 🤔
First working version:
(xt/q xt-node
'(-> (from :some-table [* some-column]) ; `some-column` not required, just for clarity
(unnest {:search-column $vals})
(where (= some-column search-column))
(without :search-column))
{:args {:vals ["foo" "bar"]}}) Is there a better way?
Used the unnest-where pattern from here: https://discuss.xtdb.com/t/beginner-datalog-query-in-xtql-v2-w-clojure/382/6
yep, that's still the recommendation - when we next spend some time on XTQL this'll be the kind of thing we'll strongly consider adding 🙂
Thanks @jarohen! How does one pass in parameters when writing the equivalent query in SQL?
(xt/q node "SELECT * FROM some_table WHERE some_column IN (?, ?)" {:args ["foo", "bar"]}), if I've understood you correctly 🙂
if it's a dynamic number of params, I'd recommend something like Sean's HoneySQL, HugSQL or similar, all of which will deal with generating the right number of ?s and ,s for you 😅