Fork me on GitHub
#sql
<
2021-07-07
>
jmckitrick11:07:16

Got it! Thanks for the help and explanation.

jamescroft11:07:13

Hi, I’m on a project using java.jbc (not next) with Postgres, and I’m trying to get the database to return JSR-310 LocalDate/Times. Currently I’m getting back java.sql.Timestamp Apparently the https://jdbc.postgresql.org/documentation/head/8-date-time.html, but i’m unsure what step i’m missing to get it to return JSR-310 things. I’m using:

org.clojure/java.jdbc {:mvn/version "0.7.12"}
org.postgresql/postgresql {:mvn/version "42.2.20"}
Is there some other configuration needed?

indy12:07:02

(extend-protocol clojure.java.jdbc/IResultSetReadColumn
  java.sql.Timestamp
  (result-set-read-column [^Timestamp ts _ _]
    (->local-date ts)))
Where ->local-date will be your function to convert java.sql.Timestamp to LocalDate.

lukasz14:07:47

and overall switch from java.jdbc to next.jdbc

seancorfield17:07:35

@U06790Y4E I'd recommend switching to next.jdbc if you can, since this is supported directly. If you need to keep using c.j.j, you'll have to extend the (similar but different) protocols per indy's suggestion.

jamescroft18:07:32

@U04V70XH6 ok, thanks for the tip. Moving to next.jdbc is on the agenda, i’m trying to transition us there now and switching the dates to be java.time is one of the steps. I’ll extend the protocols for now. I originally thought i wouldn’t have to do that based off the Postgres docs, but I don’t fully understand each layer at the mo

seancorfield20:07:39

You can do it at the raw JDBC layer if you tell the driver what type the column is -- but c.j.j and next.jdbc don't know that information (in any portable, useful way) so they just traffic in Objects. Some drivers accept Java Time types and will coerce them to SQL types -- but PG won't even do that for java.util.Date without some assistance, which is where the next.jdbc.date-time namespace comes in: it adds automatic support for setting parameters based on both Java Time types and java.util.Date, and three functions that add support for reading SQL date/time types as different Java Time types.