I create a simple function with insert! inside a doseq
(defn persist-all-subscription-results
[subscription-results]
(with-open [connection (jdbc/get-connection db-spec)]
(doseq [result subscription-results]
(sql/insert! connection :analysis result))))
This does insert the first hash-map in the database. If I read this correctly, it seems postgres does not like the result and generates an error
org.postgresql.util.PSQLException
ERROR: syntax error at or near "-" Position: 30
QueryExecutorImpl.java: 2553 org.postgresql.core.v3.QueryExecutorImpl/receiveErrorResponse
QueryExecutorImpl.java: 2285 org.postgresql.core.v3.QueryExecutorImpl/processResults
QueryExecutorImpl.java: 323 org.postgresql.core.v3.QueryExecutorImpl/execute
PgStatement.java: 481 org.postgresql.jdbc.PgStatement/executeInternal
PgStatement.java: 401 org.postgresql.jdbc.PgStatement/execute
Any pointers ??
Did I do something silly?shooting from the hip you have snake-case
and need to underscore into snake_case
@jr0cket If you’re using the latest next.jdbc
, there should be a next.jdbc/snake-kebab-opts
that you can pass into insert!
as a final argument to do that automatically.
See https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.2.659/api/next.jdbc#snake-kebab-opts
Oh yes, I should add the snake-kebab-opts thing as another argument to insert! I seemed to have though next.jdbc did it automatically, wooops...
Success. Thank you all.
I think c.j.j did too many automatic adjustments to column names both going in and out so next.jdbc
defaults to doing nothing and leaves it up to users. If everything you are doing is with kebab-case
<-> snake_case
then you can use with-options
to create a connectable that automatically applies those options to operations (caveat: with-transaction
and get-connection
return unadorned Java objects that need wrapping via with-options
again in those contexts).