Hi, I need an extra help with insert-into. I have a data like:
(def my-data [{:value1 "1", :mymap {:map2 "42"}}])
this can potentially be several maps and I want to insert-many.
(jdbc/execute! datasource (-> {:insert-into :Table :values my-data} (sql/format)))
but I got an error
Execution error (PSQLException) at org.postgresql.core.v3.QueryExecutorImpl/receiveErrorResponse (QueryExecutorImpl.java:2553).
ERROR: syntax error at or near ")"
The sql query generate will be
(-> {:insert-into :Table
:values [{:value1 "1" :mymap {:map2 "42"}}]}
(sql/format))
;; => ["INSERT INTO Table (value1, mymap) VALUES (?, ())" "1"]
I feel I am missing something here. Not sure if I need to add something specific into sql/format
@iagwanderson Which version of HoneySQL are you using? And what does it mean to have a column whose value is a hash map?
version "1.0.461", the hashmap is coerced to jsonb fields
With 2.0, you can do this:
user=> (-> {:insert-into :Table
#_=> :values [{:value1 "1" :mymap [:lift {:map2 "42"}]}]}
#_=> (sql/format))
["INSERT INTO Table (value1, mymap) VALUES (?, ?)" "1" {:map2 "42"}]
I'm not sure what the solution is in 1.0, probably wrapping it in (sql/param ..)
?Nope, not sql/param
I tried, sql/param too.
I'm not sure if it's possible with 1.0.
(well, I'm sure it is possible but I don't know how, off the top of my head)
I will investigate this further later on and fix my situation now using next.jdbc directly. Would be good idea to create an issue as enhancement to support this? At least for tracking and generate docs if current facilities allow
It works in 2.0 as shown above. If it isn't possible in 1.0, it won't get fixed at this point.
If you figure out how to do it in 1.0, I'd accept a PR for the docs for 1.0, but I'd encourage you you start upgrading to 2.0 at this point: you can depend on both versions at the same time -- different group IDs and different namespaces -- so you could use 2.0 for just that one insert if you wanted, and stay with 1.0 for everything else.
> If you figure out how to do it in 1.0, I'd accept a PR for the docs for 1.0, but I'd encourage you you start upgrading to 2.0 at this point: you can depend on both versions at the same time -- different group IDs and different namespaces -- so you could use 2.0 for just that one insert if you wanted, and stay with 1.0 for everything else. nice, it makes sense. thank you!