xtdb

Stef Coetzee 2024-08-11T20:19:06.439949Z

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
Stef Coetzee 2024-08-11T20:24:38.317199Z

Not sure how to access $vals in this query:

(xt/q node '(-> (from :some_table [*])
                ...)
      {:args {:vals ["foo" "bar"]}}) 

Stef Coetzee 2024-08-11T20:43:00.243199Z

Relatedly, how does one provide arguments to XTSQL? 🤔

Stef Coetzee 2024-08-12T00:37:57.528919Z

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"]}}) 

Stef Coetzee 2024-08-12T00:42:42.126639Z

Is there a better way?

Stef Coetzee 2024-08-12T00:45:46.912789Z

Used the unnest-where pattern from here: https://discuss.xtdb.com/t/beginner-datalog-query-in-xtql-v2-w-clojure/382/6

👌 1
jarohen 2024-08-12T08:55:09.143969Z

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
Stef Coetzee 2024-08-12T09:39:11.137599Z

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

🙏 1
jarohen 2024-08-12T09:41:20.849689Z

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

1
jarohen 2024-08-12T09:42:07.127609Z

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