Hi, stupid question from a Clojure beginner: I have an INSERT
with an optional parameter like INSERT INTO table (name, color) VALUES (:name, :color)
. Let's say :color
is optional and the name is create-table!
. Now if I do (create-table! { :name "Test"})
, it will fail with ExceptionInfo Parameter Mismatch: :color parameter data not found.
I would imagine this is a frequent thing but I couldn't find an easy solution to this problem. Could you help me please? Can I somehow mark :color
as being optional?
@emboss if you're doing simple inserts you can use jdbc's insert!
function instead of trying to template the insert statement
@rymndhng I managed to use --~ (if (:color params) ":color" "NULL")
in the template. It actually works but it feels wrong... So you think I'm better off using a JDBC insert directly?
yeah, I prefer using HugSQL for building complex queries (for reading), but inserts are generally straight forward enough using raw jdbc
(jdbc/insert! db "table-name" {:name "Test"})
(jdbc/insert! db "table-name" {:name "Test" :color "some-color"})
OK, makes perfect sense. I was just wondering if I am missing something obvious because it wasn't mentioned anywhere I looked and it was literally the second thing that I stumbled upon when starting to play with it 🙂
Thank you so much for your help and time, much appreciated!
no worries 🙂 enjoy clojuring!
I do and I will, thanks 😉