如何解决问题:pyodbc.ProgrammingError: ('字符串数据,右截断:长度162缓冲区160', 'HY000')

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

我在将数据插入数据库时遇到问题,可能是因为我的参数太长。有没有办法增加缓冲?

问题:

pyodbc.ProgrammingError: ('String data, right truncation: length 162 buffer 160', 'HY000')

出现问题的我的代码:

@event.listens_for(engine, 'before_cursor_execute')
def receive_before_cursor_execute(conn, cursor, statement, params, context, executemany):
    print("FUNC call")
    if executemany:
        cursor.fast_executemany = True
python sql buffer pyodbc
1个回答
0
投票

更有可能与类型转换有关。 当我尝试将看起来像“2023-07-13T17:55:28.075Z”的字符串日期时间直接保存到数据库中的日期时间列时,我遇到了类似的错误。 首先将其转换为实际日期时间解决了问题:

datetime.fromisoformat(created_at)
© www.soinside.com 2019 - 2024. All rights reserved.