Fork me on GitHub
#sql
<
2022-05-20
>
Em15:05:15

Fun next-jdbc behavior Hey y’all, I just spent most of the afternoon discovering this and I was wondering if the behavior is a feature/expected/I just don’t understand something, or maybe it’s a bug in next-jdbc, or who knows. The README of the project says to say hi in slack ,so I’m saying hi here! basically when I use get-datasource with the :jdbcUrl argument format, I get a ; (err) No suitable driver found for jdbc: error when the dbtype is postgres but not when it’s postgresql.

(ns hello.world
  (:require [next.jdbc :as jdbc])
;this works
(jdbc/execute! (jdbc/get-datasource "jdbc:")
               ["select * from user limit 1"])
;this works
(jdbc/execute! (jdbc/get-datasource {:dbtype "postgresql" :name "db_name" :host "localhost" :port "3300"})
               ["select * from user limit 1"]))
;this also works
(jdbc/execute! (jdbc/get-datasource {:dbtype "postgres" :name "db_name" :host "localhost" :port "3300"})
               ["select * from user limit 1"]))
;throws the 'no suitable driver' error
(jdbc/execute! (jdbc/get-datasource "jdbc:")
               ["select * from user limit 1"])
I would have expected postgres to work just as well as postgresql since they’re mentioned side by side https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.2.780/api/next.jdbc?q=get-datasource#get-datasource

seancorfield15:05:08

If you're using :jdbcUrl, it gets passed straight to JDBC and next.jdbc has basically nothing to do with it -- so you need to pass a URL that JDBC understands.

seancorfield15:05:52

If you use the next.jdbc hash map format -- with :dbtype -- then next.jdbc can provide some shortcuts and aliases for things. It's why I recommend using the hash map approach.

Em15:05:14

ah, interesting!

Em15:05:17

jeez. i truly did just spend, like, half of my work day tracing down 2 missing characters. anyway, thanks for the speedy reply!

seancorfield15:05:03

JDBC is a labyrinth, unfortunately, and behavior varies a lot across different databases, despite it being a "standard". next.jdbc does what it can to make that a bit less painful but there are some things it can't "fix" 🙂 For example, PostgreSQL is alone in returning an entire row from an insert I believe -- other databases just return the keys. SQL Server only returns table names in ResultSet data in some situations, Oracle never does, other databases always do. Some databases are case-sensitive, some aren't. One database returns nil for a ResultSet instead of an empty ResultSet (like all the other databases do).

seancorfield15:05:06

MySQL has a different precedence in SQL for SET than all the other databases 🙂 (I use MySQL primarily so this is a pain I feel regularly).

Em15:05:28

oh gosh, what a headache! all the more props to you