Pyodbc:将腌制的Python模型插入MS SQL Server时出错

问题描述 投票:2回答:1

曾尝试对这一问题进行一段时间的故障排除,但遇到了很多问题。想知道是否有人见过此。

我正在尝试在Python中pickle一个简单的RandomForestClassifier(sklearn),并使用pyodbc将其保存到MS SQL Server数据库。特别是,我正在使用UPDATE语句,因为我正在更新先前已训练的模型。

这是我正在使用的查询:

RF_serialized = pickle.dumps(RF)

RF_serialized_ins = str(RF_serialized)[1 : ] # doing this to cut off the leading 'b' from 
                                             # Python's byte data, per suggestions from other answers

q = "UPDATE table \
    SET serializedModel = CONVERT(VARBINARY(MAX), {}) \
    WHERE IDa = {} AND \
            IDb = {} AND \
            IDc = {}".format(RF_serialized_ins, "x", "y", "z")

不过,我不断收到以下非特定类型的错误:

pyodbc.ProgrammingError: ('42000', '[42000] [Microsoft][ODBC Driver 17 for SQL Server]Syntax error, permission violation, or other nonspecific error (0) (SQLExecDirectW)')

[有人遇到过吗?我肯定ID和过滤器正确,等等。目标列的数据类型为VARBINARY(MAX)。一个想法:腌制的物体太大吗?对象的大小:

print("Type of python object:", type(RF_serialized))
print("The size of the pickled RF model is:", RF_serialized.__sizeof__())
Type of python object: <class 'bytes'>
The size of the pickled RF model is: 5487942
python sql-server pickle pyodbc
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.