cl-dbi icon indicating copy to clipboard operation
cl-dbi copied to clipboard

Preparing statement with lists

Open simkoc opened this issue 5 years ago • 2 comments
trafficstars

I have the following issue:

(dbi:with-connection (con :postgres
                          :username "test"
                          :database-name "test")
  (dbi:execute
     (dbi:prepare con
                  "SELECT a,
                          b
                   FROM T
                   WHERE c = ? AND
                         a IN ? AND")
     2
     (list "1" "2")))

results in

DB Error: syntax error at or near "$2" (Code: 42601)

But

(dbi:with-connection (con :postgres
                          :username "rc-study-manager"
                          :database-name "rc-study")
  (dbi:execute
     (dbi:prepare con
                  "SELECT a,
                          b
                   FROM T
                   WHERE c = ? AND
                         a IN ('1', '2')")
     2))

does not.

How can I prepare a statement when I have list(s) as parameters?

simkoc avatar Mar 07 '20 19:03 simkoc

Please try this:

(dbi:with-connection (con :postgres
                          :username "test"
                          :database-name "test")
  (apply #'dbi:execute
         (dbi:prepare con
                      "SELECT a,
                          b
                   FROM T
                   WHERE c = ? AND
                         a IN ? AND")
         2
         (list "1" "2")))

kat-co avatar Mar 12 '20 17:03 kat-co

Sorry for the delay. I still get the same exception.

simkoc avatar Mar 17 '20 10:03 simkoc