xtdb 2024-08-11

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.

✅ 1

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?

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 🙂

1

Thanks @jarohen! How does one pass in parameters when writing the equivalent query in SQL?

🙏 1

(xt/q node "SELECT * FROM some_table WHERE some_column IN (?, ?)" {:args ["foo", "bar"]}), if I've understood you correctly 🙂

1

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 😅

💯 1