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
Type detection seemingly order-dependent in PreparedBatch #1765
Comments
Does the problem persist if you install the |
Installing At the same time, it still feels a little buggy that a thing that works in isolation (setting a Thanks for the fast reply! |
I agree, it's an odd behavior. JDBC drivers have different requirements around |
Ah, I am not so sure we can fix this as stated originally.
This will lose all information about the You could instead write:
and that has some hope of working. If not, we can consider it a bug. |
I'll certainly defer to your expertise, but it still seems very strange to me that this works: batch.bind("uuid", (UUID)null);
...
batch.bind("uuid", UUID.randomUUID()); ...but this doesn't: batch.bind("uuid", UUID.randomUUID());
...
batch.bind("uuid", (UUID)null); If anything (and knowing nothing about the internals), I would have expected exactly the opposite (e.g. that in the first case, the batch doesn't have enough information to infer the type of the "uuid" column when binding Thanks! |
@jon-signal I agree with your assessment that the behavior in this case isn't exactly intuitive. It's accidental and unfortunately it's long-standing, and probably not something we can fix in all cases. The default UUID binding strategy in Jdbi core (bind as To avoid this, in the In prepared batches, one way we achieve performance gain is by relying on the type of the bound arguments not to change in an incompatible way from row to row. So in your working case:
the type of the first argument as far as Jdbi can see is In the non-working case, the type of the first argument is One thing we can do is to add a The general fixes:
If we went back in time, we might not have added the core Let me know if you think of a good way to make the situation better. |
Understood. This is a way more thoughtful explanation and fix than I think I earned by gesturing vaguely in the direction of a the problem, but thank you! Totally understand the constraints on the problem space, and I think the changes in #1768 make a ton of sense. Thank you for addressing this! I'm more than happy with the explanation and updates, and certainly consider this issue resolved for my part (but don't want to be presumptuous and close it if you think there's still more to do). |
Let's have this issue be to add some kind of explanation to the docs :) |
Closing, still tracked in #2390. |
We've run into a curious problem where we'll get a
BatchUpdateException
("column [X] is of type uuid but expression is of type character varying") if we attempt to execute a prepared batch against Postgres with a non-null UUID in one row and a null UUID in the next row. Here's a test case:Three of the tests pass, but
testInsertNonNullFirst
fails with an exception. Here's the pom, for your convenience:I'll plan on digging in and seeing if I can provide a more helpful analysis shortly.
The text was updated successfully, but these errors were encountered: