fix: the JDBC reWriteBatchedInserts=true option could cause errors in DML batches #713
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
reWriteBatchedInserts=true
JDBC option can cause the PG JDBC driver to execute a batch that contains different SQL statements, where one of the SQL statements in the middle of the batch must be described. The latter happens if the statement contains at least one untyped parameter. The JDBC driver sends all timestamp and date parameters as untyped, meaning that statements with parameters of those types could cause this problem. PGAdapter would then try to describe the statement as part of the batch, which is not possible, as ExecuteBatchDml does not support PLAN mode.ExecuteBatchDml will normally throw a BatchUpdateException if something goes wrong in a batch. It is however possible that the entire batch fails, for example if the transaction has been aborted before the batch is sent and retrying the transaction fails because of concurrent modifications. Those errors would not be handled properly in PGAdapter and could cause PGAdapter to return the generic exception 'Statement result cannot be retrieved before flush/sync' instead of the actual underlying exception. This PR also adds error handling and tests for that possibility.