简体   繁体   English

如何使用truncate在mysqldb中进行事务

[英]How to do a transaction in mysqldb with truncate

I am trying to truncate a table and then do some inserts and then commit it all at the end. 我试图截断一个表,然后进行一些插入,然后在最后全部提交。 However doing the following clears the table immediately: 但是,执行以下操作会立即清除表:

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

How would I delay the 'truncate' until after I commit the transaction? 我如何将“截断”延迟到提交事务之后?

You can't use TRUNCATE within a transaction as it automatically commits. 您不能在事务中使用TRUNCATE ,因为它会自动提交。 Better to do something like this: 最好做这样的事情:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM