简体   繁体   English

Snowflake Connector for Python 中的事务和回滚

[英]Transaction and Rollback in Snowflake Connector for Python

I am using the Snowflake Connector for Python as follows:我正在使用 Python 的雪花连接器,如下所示:

ctx = snowflake.connector.connect(user=username, password=password, account=account, warehouse=warehouse)
cs = ctx.cursor()
try:
 cs.execute(u"begin")
 cs.execute("TRUNCATE table1")
 cs.execute("TRUNCATE table2")
 cs.execute("TRUNCATE table3")
 ctx.commit()
except snowflake.connector.errors.ProgrammingError as e:
  ctx.rollback()
  print("ERROR" + e.msg)
finally:
  cs.close()
  ctx.close()

Essentially I want to rollback if there are any issues with any of the SQLs (TRUNCATES).基本上,如果任何 SQL (TRUNCATES) 有任何问题,我想回滚。 But this code doesn't seem to rollback.但是这段代码似乎没有回滚。

Any ideas on what could be causing this?关于可能导致这种情况的任何想法?

From the docs , you will have to set autocommit to False in order for Rollback to work, however, i am having trouble getting it to work even with it set.文档中,您必须将自动提交设置为 False 才能使回滚工作,但是,即使设置了它,我也无法让它工作。 Please post your findings.请张贴你的发现。

ctx = snowflake.connector.connect(autocommit=False,user=username, password=password, account=account, warehouse=warehouse)

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

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