【问题标题】:Error on updating nvarchar(max) column from Python从 Python 更新 nvarchar(max) 列时出错
【发布时间】:2017-10-13 13:02:32
【问题描述】:

我正在更新 Google 反向地理编码的输出(JSON 格式),

cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=localhost;DATABASE=mydb;UID=test;PWD=abc@123;autocommit=True')
cursor = cnxn.cursor()
wp = urllib.request.urlopen("http://maps.googleapis.com/maps/api/geocode/json?latlng=18.5504,73.9412&sensor=false")
pw = wp.read()
#print(pw)
cursor.execute("UPDATE GEOCODE_tbl SET JSON_str = ? WHERE GEOCODE_ID = ?", pw,749904)
print('Done')
cnxn.commit()

但它给出了错误

('22018', '[22018] [Microsoft][ODBC SQL Server Driver][SQL Server]Operand type clash: image is incompatible with nvarchar(max) (206) (SQLExecDirectW)')

这是什么错误? JSON_str 列有这样的 JSON 输出,所以我正在为那些 JSON_str 列为 NULL 的列执行任务。

有人知道吗?

【问题讨论】:

  • 您确定pw 是str 类型吗?也许试试cursor.execute("UPDATE GEOCODE_tbl SET JSON_str = ? WHERE GEOCODE_ID = ?", (str(pw), 749904))?
  • @FlipperPA 是的,将它们转换为 str 工作。非常感谢!!!
  • 太好了,我会把它转换成答案!

标签: python json python-3.x pyodbc


【解决方案1】:

值pw 不是str 类型。尝试将您的查询转换为:

cursor.execute("UPDATE GEOCODE_tbl SET JSON_str = ? WHERE GEOCODE_ID = ?", (str(pw), 749904))

祝你好运!

【讨论】:

    猜你喜欢
    • 2021-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多