【问题标题】:Atomicity with multiple DML's in Snowflake Transactions雪花事务中具有多个 DML 的原子性
【发布时间】:2021-07-02 14:45:57
【问题描述】:

您好,我有一个要求,

BEGIN TRANSACTION NAME <name_identifier of the transaction>;

<insert statement> on table ABC

<delete statement> on table ABC

COMMIT;

现在我想要两个 sql 都应该完成或没有。 任何一条语句都不应该被执行。

我应该如何做到这一点。自从我尝试过。

create or replace table test_table(user_id integer,ip_address text,user_agent text,email text);
create or replace table test_table_copy(user_id integer,ip_address text,user_agent text,email text);

begin transaction name test_transaction;

insert into test_table_copy values(100,'1.1.1.1','ua_1','abc1@gmail.com');

insert into test_table values(100,'1.1.1.1','ua_1','abc1@gmail.com');

-- will fail as table name does not exist
delete from test_tablee where user_id = 100;

commit;

尽管 delete 语句失败,但我仍看到 insert 的行为发生。

我如何在这里实现全部完成或未完成的事情。

谢谢

【问题讨论】:

    标签: snowflake-cloud-data-platform snowflake-schema


    【解决方案1】:

    要中止事务,您可以将:TRANSACTION_ABORT_ON_ERROR 设置为 TRUE。

    TRUE:非自动提交事务被中止。在该事务中发出的所有语句都将失败,直到执行提交或回滚语句以关闭该事务。

    ALTER SESSION SET TRANSACTION_ABORT_ON_ERROR = TRUE;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-17
      • 1970-01-01
      相关资源
      最近更新 更多