On 10/03/2022 04.08, Vladimir Sitnikov wrote:

Have you tried PreparedStatement#addBatch + #executeBatch APIs and reWriteBatchedInserts=true connection option?
It might yield the expected speedup without resorting to PG-specific APIs and syntax like COPY.


Yes, I tried addBatch + executeBatch. It was very inconvenient in my specific case. I used all over the place postgresql extension

  insert into table(c1, c2, c3, ...) values (....) RETURNING *

this way I can "get back" the data inserted. The PG extension INSERT/UPDATE/DELETE ... RETURNING *
was so convenient to: 1. check  the data, 2. autoincrements, 3. Return updated data, etc, that I started to use in with almost all insert/update/delete.
The  #executeBatch returns the number of rows changed, not the data as with the RETURNING *

Vladislav