代码之家  ›  专栏  ›  技术社区  ›  Daren Nevic

AWS红移等效于T-SQL的begin-try/begin-catch错误处理

  •  0
  • Daren Nevic  · 技术社区  · 3 年前

    红移中的re是否等效于以下T-SQL代码段?

       BEGIN TRY  
         { sql_statement | statement_block }  
       END TRY  
       BEGIN CATCH  
         [ { sql_statement | statement_block } ]  
       END CATCH  
       [ ; ] 
    

    如何处理红移中的错误? 例如,我得到了以下SQL代码

    begin;
    drop table if exists [table_new];
    drop table if exists [table_old];
    create table [table_new] as
        select * from [table_source];
    alter table [current_table] rename to [table_old];
    alter table [table_new] rename to [current_table];
    commit;
    

    从本质上讲,数据是从视图中提取并放入表中的。 如果视图中的任何源为空,将导致错误,如果我重新运行上述代码,它将返回以下内容。

    [25P02]错误:当前事务中止,在事务块结束之前忽略命令

    本质上,如何在出错时回滚事务?

    非常感谢

    0 回复  |  直到 3 年前