Honeysql - Clojure - How to pass a vector as arguments into Values in insert-into statement

572 views Asked by At

I'm working with Clojure using honeySql for formatting SQL statements. The statement will run on a MySQL DB.

I'm looking for a way to pass an argument in the params and use it as the values in the inset-inro statement.

This is the statement I'm looking for :

INSERT INTO some_table
(a, b, c)
VALUES (1, 2, 3),
       (4, 5, 6);

insert attempt:

(def insert-demo
  (-> (insert-into :some_table)
      (columns :a :b :c)
      (values [:param :vals)))

This is the way I'm calling to the format function:

(sql/format dbcst/insert-demo {:inline true
                               :pretty true
                               :params {:vals [[1 2 3] [4 5 6]]}})

Unforentualy this won't work.

I tried a few options in the values section no success so far.

(values [:?vals])

(values :?vals)

Is there a way to pass a vector and use it as a param?

To be clear: I'm looking for a way to pass values dynamically.

Thanks

1

There are 1 answers

1
JaeyeonJo On

Try this :

(def insert-demo
  (-> (insert-into :some_table)
      (columns :a :b :c)
      (values [[1 2 3] 
               [4 5 6]])))