Fork me on GitHub
#sql
<
2019-02-07
>
Joelle Wakim18:02:04

Hello @seancorfield, I am trying to insert a batch entry using insert-multi! fn but is not doing it in one single insert statement. Can you assist please, thank you

Joelle Wakim18:02:25

(j/insert-multi! db (keyword (rule :table)) (conj [] :id :eid :prop :val :process :tx) @records)

seancorfield18:02:06

Are you on PostgreSQL?

seancorfield18:02:15

Then you probably need to specify :rewriteBatchedStatements true in your db-spec so that MySQL handles the batched insert correctly. PostgreSQL has a similar issue @joelle.wakim

seancorfield18:02:07

Here's the JIRA issue for PostgreSQL https://dev.clojure.org/jira/browse/JDBC-174 -- I'll update that with a note about MySQL too.

Joelle Wakim18:02:22

Ok thank you, I will change it and will let you know if it works

seancorfield18:02:31

In particular, be aware of the caveats given in the answer to that SO issue.

seancorfield18:02:02

(this sort of thing is horribly DB-specific, unfortunately, in the same way that streaming of result sets is also very DB-specific)

seancorfield18:02:00

I've updated JDBC-174 -- I'll try to figure out a better way to handle this in next.jdbc but the rewritten SQL that PostgreSQL/MySQL produce here is not accepted by all databases, which is why java.jdbc tries to do things the way it does today.

Joelle Wakim18:02:51

@seancorfield I changed the db-spec map and added :rewriteBatchedStatements true, but the code is still writing multiple insert statements and not one single statement, could the issue be something else? Thanks

seancorfield18:02:33

@joelle.wakim No idea. Unfortunately each database driver has its quirks. Feel free to add repro steps to JDBC-174 (linked above) and I'll try to take a look when I get some time.

seancorfield19:02:33

(also add notes of how you confirming that you get multiple inserts and information about how many rows you're trying to insert etc)

Joelle Wakim19:02:13

@seancorfield ok thank you, I can see the multiple insert statements from Mysql log file. Just a question does the same apply to MariaDB?

seancorfield19:02:41

In theory, this is purely a feature of the database driver rather than the underlying database that you are connecting to. That said, if you use a driver that is not compatible with the database, you'll run into problem.

seancorfield21:02:23

@joelle.wakim Could you add the dependencies/versions you're using to that ticket too pls? So I know what version of the driver to attempt to repro with.