From 203cb05ac1f1974f4233a9d6ec864aeda0d46532 Mon Sep 17 00:00:00 2001 From: Doug Beatty <44704949+dbeatty10@users.noreply.github.com> Date: Fri, 15 Dec 2023 09:31:14 -0700 Subject: [PATCH] Explain how transactions (and rollbacks) are handled for incremental strategies (#4655) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Preview](https://docs-getdbt-com-git-dbeatty-explain-incremental-957f61-dbt-labs.vercel.app/docs/build/incremental-models#how-do-incremental-models-work-behind-the-scenes) ## What are you changing in this pull request and why? resolves #4635 The goal of this issue is to document the answer to this question from https://github.com/dbt-labs/dbt-core/issues/7011#issuecomment-1443698015: > For the DML, we know that only the delete+insert strategy will work, and not merge. With delete+insert incremental strategy, does Dbt wrap both in a single transaction? If not, and they are treated as 2 separate transactions that would be bad. For example, the delete could succeed, and the subsequent insert could fail. The table would then be left with deleted records = Not Good. Can you elaborate on how Dbt already handles that. I cannot find it anywhere in the doc. ### 🎩 image ## Checklist - [x] Review the [Content style guide](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/content-style-guide.md) so my content adheres to these guidelines. --------- Co-authored-by: mirnawong1 <89008547+mirnawong1@users.noreply.github.com> --- website/docs/docs/build/incremental-models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/docs/build/incremental-models.md b/website/docs/docs/build/incremental-models.md index 46788758ee6..2a247263159 100644 --- a/website/docs/docs/build/incremental-models.md +++ b/website/docs/docs/build/incremental-models.md @@ -174,7 +174,7 @@ dbt's incremental materialization works differently on different databases. Wher On warehouses that do not support `merge` statements, a merge is implemented by first using a `delete` statement to delete records in the target table that are to be updated, and then an `insert` statement. -Transaction management is used to ensure this is executed as a single unit of work. +Transaction management, a process used in certain data platforms, ensures that a set of actions is treated as a single unit of work (or task). If any part of the unit of work fails, dbt will roll back open transactions and restore the database to a good state. ## What if the columns of my incremental model change?