-
Notifications
You must be signed in to change notification settings - Fork 29
Batch update with some invalid values fails for all rows #89
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
Comments
So if I understand correctly, you would like the insert for the first to succeed and the second to fail. see https://www.postgresql.org/docs/current/tutorial-transactions.html for more details Dave |
Not quite, I'm perfectly fine with the insert failing and actually think this is more correct than doing a partial insert as some other databases/ODBC drivers do. But it would be great to have some information about which rows resulted in an error and this is something that I.e. the problem is not (so much) returning |
Unfortunately the server does not provide that information. It doesn't know that the first one succeeded since it was all done in one insert.
While we do get the error message, we don't know if it is the 1st or 2nd value that failed |
Just trying to understand: how does the driver manage to send multiple parameters to the server? From looking at the code it seems like it does |
Can you show me the code you are thinking it is using.
|
I've been looking at the part of Line 1140 in 1fbc3b2
Lines 1241 to 1244 in 1fbc3b2
Interesting, wouldn't this run into some kind of limitation (number of parameters or total length of the command) for even relatively small amounts of data? |
it does, but not as much as one would think. It will handle quite a few values. |
I would just enable logging on the server to see how it does this. |
Good point, thanks, this is indeed even simpler. And what I see is that the driver (at least 13.02 version from Debian Bookworm) just sends multiple semicolon separated statements to the server in a single request, e.g. for my test I see the following
If the "at character N" part is always present (but I'm not at all sure about this), it looks like it would be possible to find the row which resulted in the error by remembering the positions of the statement boundaries for each row. But now I also wonder if this is really the most efficient way to do bulk inserts/updates with Postgres, at the very least repeating the entire query many times like this should consume much more bandwidth than preparing it once/reusing it it for all rows? |
Uh oh!
There was an error while loading. Please reload this page.
Suppose there is the following table in the database:
and consider a program which does something like the following (simplified):
When using SQL Server with either Microsoft ODBC driver or FreeTDS,
rc
isSQL_SUCCESS_WITH_INFO
andstatus
array is filled with{ SQL_PARAM_SUCCESS, SQL_PARAM_ERROR }
which is nice because it allows the application to determine which row(s) contained values that resulted in an error.When using PostgreSQL ODBC driver (v13.02, but from examining Git history it doesn't look like there have been any changes here even in the latest version),
rc
isSQL_ERROR
andstatus
containsSQL_PARAM_ERROR
for both elements, which doesn't provide any useful information.Is this behaviour intentional and, if not, would it be possible to change it to be more consistent with other ODBC drivers and, also, more useful?
The text was updated successfully, but these errors were encountered: