我想知道,在调用session.commit()之后SQLAlchemy可以重新打开会话吗?以下代码有时(并非总是,大多数情况下没有错误)会产生错误END;
/
。非常简化的代码,但它应该显示操作的顺序:
ProgrammingError('(ProgrammingError) (1146, "Table 'dbname.tmp_table' doesn't exist")
我使用sqlalchemy和mysql 5.5并使用mysql的with create_session() as session:
session.execute("DROP TEMPORARY TABLE IF EXISTS dbname.tmp_table")
session.execute("CREATE TEMPORARY TABLE dbname.tmp_table (field list)")
session.commit()
while loop_condition is valid:
# This line gives accidentally errors
session.execute("INSERT INTO dbname.tmp_table (fields) SELECT ...")
# A couple of another data manipulations on DB server
...
session.execute("TRUNCATE TABLE dbname.tmp_table")
session.commit()
session.execute("DROP TEMPORARY TABLE IF EXISTS dbname.tmp_table")
session.commit()
来缓存一些事务的聚合结果。我知道临时表只能在创建它的会话中访问。所以我唯一的建议是SQLALchemy的会话有时会在提交后重新打开MySQL的实际会话。有可能还是有其他正确的解释?