Python 的 Snowflake 连接器中的事务和回滚

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

我正在使用 Python 的 Snowflake 连接器,如下所示:

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()

本质上,如果任何 SQL (TRUNCATES) 出现任何问题,我想回滚。但这段代码似乎没有回滚。

有什么想法可能导致这种情况吗?

python python-3.x transactions rollback snowflake-cloud-data-platform
2个回答
2
投票

docs中,您必须将自动提交设置为False才能使回滚工作,但是,即使设置了它,我也无法使其工作。请发表您的发现。

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

0
投票

尽管我设置了 autocommit = False,但我在设置回滚时遇到了问题,还有其他方法可以做到这一点吗?

© www.soinside.com 2019 - 2024. All rights reserved.