Been a long time since working with raw SQL, it is a breeze with next-jdbc, but I'm stumbling now with execute-batch! and postgresql timestamp formats. Our document date is a date without time component (intentionally, eg. "2025-03-07"). I add the time component before inserting, like this
(-> (:date document)
tick/date
(tick/at "10:00")
tick/inst)
And then the batch insert as follows
(next/with-transaction [tx (create-jdbc-postgres-datasource cache-config)]
(log/info "Inserting " (count coll) " documents to cache db.")
(let [parameters (mapcat (fn [[exp res]] (to-insert-batch-parameters exp res)) coll)]
(next/execute-batch! tx insert-into-sql parameters {})))
I've required [next.jdbc.date-time] as suggested in the docs to get some magic for date conversions, but I still get errors and now I'm wondering does the date-time magic reach batch insert or do I have to emit the date as a java.util.Date and rely on the JDCB-driver? The column is of TIMESTAMP format.
ERROR: column "calculated_at" is of type timestamp without time zone but expression is of type numeric
Hint: You will need to rewrite or cast the expression.
What am I missing here?> do I have to emit the date as a java.util.Date
Should probably be java.sql.Date.
A quick look at the impl suggests that requiring next.jdbc.date-time should make it all work with execute-batch! as well since the parameters passed to that function still go through set-parameter.
java.sql.Date is the only type that uses .setDate and not .setTimestamp.
Thanks, my initial look on the impl also suggested that it should work. Good point on the java.sql.Date
Also, just in case - there's no real need in tick with modern java.time.*. Despite interop, I personally find the latter much clearer w.r.t. intent and outcomes.
Agree, tick was introduced ~4 years ago so following local code base conventions for now.
My data looks correct albeit I've been staring at it for the last few hours so I might just not see something. This is that is printed out using println , first is the raw value, type is from type
ts #inst "2025-03-07T12:13:07.289-00:00" type java.util.DateJust to double-check something - what does (-> next.jdbc.prepare/SettableParameter :impls (get java.util.Date) :set-parameter) return?
Aaaaand, PEBKAC. picard-facepalm My sql string had two columns in wrong order...
or the parameter list awesome depends how one wants to interpret it