-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix to ignore computed columns during BulkCopy #1562
Fix to ignore computed columns during BulkCopy #1562
Conversation
76b9ed8
to
7282212
Compare
Thanks for the contribution @alagrede, the team will test this and get back to you with the results. |
hi @alagrede Apologies it took so long to get back to you on this, this had fallen through the cracks.. We had discussed this within our team we are ok to add this to the driver could you please resolve the conflicts in your branch? Also, we would rather not add server version checks in the driver, I think it should be fine to just check for is_computed since if it was not supported that column would not be returned. Thank you for your contribution. |
7282212
to
0a69e78
Compare
Hi @lilgreenbird |
c2e3b3f
0a69e78
to
c2e3b3f
Compare
Hello,
I'm facing a problem with the bulk API for batch insert with computed columns.
I'm using an SQL table with computed columns like
My insert query uses for bulk:
insert into myTable (id, json) values (?, ?)
The current behavior of the driver is to reject the query with:
java.sql.BatchUpdateException: The column "vcol1" cannot be modified because it is either a computed column or is the result of a UNION operator.
After investigating and testing this fix on my project, there is no specific reason to reject the batch insert. The current Bulk code simply reads and compares all the columns found in the table.
I updated the current code to ignore irrelevant computed columns when inserting in bulk and it works like a charm.
Currently, the relevant documentation does not mention any limitation on the computed columns (so the documentation is still true):
https://docs.microsoft.com/en-us/sql/connect/jdbc/use-bulk-copy-api-batch-insert-operation?view=sql-server-ver15
I also added a new unit test to verify and demonstrate this use case:
BatchExecutionWithBulkCopyTest#testComputedCols
EDIT: Code updated to be compatible with versions prior than SQL Server 2016
Sincerely