[postmodern-devel] Passing a list to a prepared query
Hi, I'd like to do this: (defprepared addresses-by-ids "SELECT address FROM users WHERE id IN $1" :column) and then call it like so: CLUSER> (addresses-by-ids "(1,2,3)") Is this possible? I've tried a few different approaches but keep getting errors. Many thanks for great software by the way. Seb -- Emacs' AlsaPlayer - Music Without Jolts Lightweight, full-featured and mindful of your idyllic happiness. http://home.gna.org/eap
Hey Sebastian,
(defprepared addresses-by-ids "SELECT address FROM users WHERE id IN $1" :column)
Is this possible? I've tried a few different approaches but keep getting errors.
I think that Postgres doesn't allow the right-hand side of IN to be an $-parameter. Try something like this:
(defprepared addresses-by-ids "SELECT address FROM users WHERE id = ANY($1)" :column)
I think you'll still have to convert your list to a vector for cl-postgres to be able to put it in a parameter. Best, Marijn
Quoth Marijn Haverbeke <marijnh@gmail.com>:
I think that Postgres doesn't allow the right-hand side of IN to be an $-parameter. Try something like this:
(defprepared addresses-by-ids "SELECT address FROM users WHERE id = ANY($1)" :column)
I think you'll still have to convert your list to a vector for cl-postgres to be able to put it in a parameter.
Many thanks. Seb -- Emacs' AlsaPlayer - Music Without Jolts Lightweight, full-featured and mindful of your idyllic happiness. http://home.gna.org/eap
participants (2)
-
Marijn Haverbeke
-
Sebastian Tennant