Second Brain: Crafted, Curated, Connected, Compounded on 10月02日 21:10
Snowflake事务模型解析
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本文详细解析了Snowflake的事务模型,包括自动提交模式、手动提交模式、事务控制语句等,并介绍了如何在不同层级设置事务。

By default, Snowflake operates in autocommit mode, where each statement is automatically committed after execution.

When your client changed it to manual, they switched to multi-statement transactions, where you need to explicitly commit your DML operations.

# Snowflake’s Transaction Model

It does provide mechanisms to maintain consistency when loading data in parallel. Snowflake supports ACID Transactions but with some important differences from PostgreSQL:

    Statement-level Atomicity: Each DML statement (INSERT, UPDATE, DELETE) is atomic. It either completely succeeds or completely fails.Multi-statement Transactions: Snowflake allows explicit transaction control using BEGIN, COMMIT, and ROLLBACK.Automatic Commits: By default, each statement auto-commits unless wrapped in a transaction block.

# Setting Transaction on different Levels (Account, User, Session)

It can be set at a account level (globally), user or session level:

    Account (global) -> alter account set autocommit = false;User -> alter user <username> set autocommit = false;Session -> alter session set autocommit = false;

Whereas session user and account settings overrule. See https://docs.snowflake.com/en/sql-reference/parameters#label-autocommit.

# During Stored Procedure (BEGIN TRANSACTION COMMIT ROLLBACK)

To change between these modes:

    To disable autocommit (enable manual mode):

or

    To manually commit changes after executing DML statements:
    To roll back changes:
    To return to autocommit mode from a transaction: Simply execute a COMMIT or ROLLBACK command to end the current transaction, and autocommit will be re-enabled.

The term for this manual transaction mode is “multi-statement transaction” in Snowflake terminology. More on docs here Transactions | Snowflake Documentation.


Origin: Snowflake
References:
Created 2025-04-22

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Snowflake 事务模型 ACID 自动提交 手动提交
相关文章