【问题标题】:How to do a transaction in mysqldb with truncate如何使用 truncate 在 mysqldb 中进行事务
【发布时间】:2017-12-22 15:22:53
【问题描述】:

我正在尝试截断一个表,然后进行一些插入,然后在最后全部提交。但是,执行以下操作会立即清除表:

>>> t.cursor.execute('START TRANSACTION;')
0L
>>> t.cursor.execute('TRUNCATE _tx;')
0L
# table is now cleared from truncate

如何将“截断”延迟到提交事务之后?

【问题讨论】:

    标签: python mysql sql mysql-python


    【解决方案1】:

    您不能在事务中使用TRUNCATE,因为它会自动提交。最好做这样的事情:

    >>> t.cursor.execute('DELETE FROM _tx;')
    

    【讨论】:

    • @MikhailBerlyant 嘿,别担心——我们已经联系上了(我已经给你发了一条消息)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-11
    • 2021-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多