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
pyodbc error 22018 - Operand type clash : image is incompatible with varchar(max) #839
Comments
Firstly, if at all possible, I would upgrade your driver to {ODBC Driver 17 for SQL Server}. {SQL Server Native Client 11.0} is rather old now. It might make a difference. |
It will bind as image when you are sending binary (bytes) type over the 8000 limit. If you want to insert into varchar or nvarchar column, use the Python string type instead. |
Should we close this then? |
I think so. It's similar to #835 but apparently not something that pyodbc would need to address if the user simply converted the bytes to an actual string before using it as a parameter value. There would still be the question of how SQL Server handles an arbitrary Unicode string as a parameter to a |
The query below, executed through pyODBC does not work when the database is set to Latin1_General_100_CI_AS_SC_UTF8. Declare @ccontent varchar(max), @xmldata xml [42000] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server] I tried pushing the xml content in as raw utf-8, which changed the error message to this: Declare @ccontent varchar(max), @xmldata xml [22018] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Operand type clash: image is Then when I changed the query to assume varbinary(max) it worked: Note that this means that when in a Latin1_General_100_CI_AS_SC_UTF8 encoded database you want to have large XML strings as parameter, you must resort to 'work around' some problems by pushing in UTF-8 bytestreams into SQL Server so use myparameter.encode. |
@Lexcon - Since you are using "ODBC Driver 18 for SQL Server" did you try adding |
@gordthompson Yes! this solves it too, without the workaround. Thanks! |
Environment
To diagnose, we usually need to know the following, including version numbers. On Windows, be
sure to specify 32-bit Python or 64-bit:
Issue
The destination table column is with collation 'Latin1_General_100_CI_AI_SC_UTF8'
when i try to insert into the table with a string length more than 8000 (10531) it throws me the following error.
in sql profiler trace it generates the following sql statements
i am unable to understand why it is converting the parameter type to image ?
when the string length is <8000 it works fine by using value.encode('utf-8') without any error.
The text was updated successfully, but these errors were encountered: