Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pre-hook-post-hook.md #4393

Merged
merged 20 commits into from
Nov 8, 2023
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
cb232ee
Update pre-hook-post-hook.md
mirnawong1 Nov 3, 2023
d43d129
Update website/docs/reference/resource-configs/pre-hook-post-hook.md
mirnawong1 Nov 3, 2023
f465eb8
Update website/docs/reference/resource-configs/pre-hook-post-hook.md
mirnawong1 Nov 3, 2023
35318a1
Update website/docs/reference/resource-configs/pre-hook-post-hook.md
mirnawong1 Nov 3, 2023
88f463d
Update pre-hook-post-hook.md
mirnawong1 Nov 3, 2023
a3eec5d
Update pre-hook-post-hook.md
mirnawong1 Nov 3, 2023
efe8670
Update website/docs/reference/resource-configs/pre-hook-post-hook.md
mirnawong1 Nov 3, 2023
6acedea
Update pre-hook-post-hook.md
mirnawong1 Nov 3, 2023
f2de94e
Merge branch 'current' into mirnawong1-patch-12
mirnawong1 Nov 6, 2023
bc8ab69
Merge branch 'current' into mirnawong1-patch-12
mirnawong1 Nov 6, 2023
e06123b
Merge branch 'current' into mirnawong1-patch-12
mirnawong1 Nov 7, 2023
eb7aa15
Update website/docs/reference/resource-configs/pre-hook-post-hook.md
mirnawong1 Nov 8, 2023
45bb32e
Merge branch 'current' into mirnawong1-patch-12
mirnawong1 Nov 8, 2023
45a5849
This branch was auto-updated!
github-actions[bot] Nov 8, 2023
8fb095b
This branch was auto-updated!
github-actions[bot] Nov 8, 2023
2188b7b
This branch was auto-updated!
github-actions[bot] Nov 8, 2023
25c4760
This branch was auto-updated!
github-actions[bot] Nov 8, 2023
de43f12
This branch was auto-updated!
github-actions[bot] Nov 8, 2023
8782ebc
This branch was auto-updated!
github-actions[bot] Nov 8, 2023
5e0f763
This branch was auto-updated!
github-actions[bot] Nov 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions website/docs/reference/resource-configs/pre-hook-post-hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,16 @@ If multiple instances of any hooks are defined, dbt will run each hook using the


### Transaction behavior
If you're using an adapter that makes use of transactions (namely Postgres or Redshift), it's worth noting that by default hooks are executed inside of the same transaction as your model being created.
If you're using an adapter that uses transactions (namely Postgres or Redshift), it's worth noting that by default hooks are executed inside of the same transaction as your model being created.

There may be occasions where you need to run these hooks _outside_ of a transaction, for example:
* You want to run a `VACUUM` in a `post-hook`, however this cannot be executed within a transaction ([Redshift docs](https://docs.aws.amazon.com/redshift/latest/dg/r_VACUUM_command.html#r_VACUUM_usage_notes))
* You want to insert a record into an audit <Term id="table" /> at the start of a run, and do not want that statement rolled back if the model creation fails.
* You want to run a `VACUUM` in a `post-hook`, however, this cannot be executed within a transaction ([Redshift docs](https://docs.aws.amazon.com/redshift/latest/dg/r_VACUUM_command.html#r_VACUUM_usage_notes))
* You want to insert a record into an audit <Term id="table" /> at the start of a run and do not want that statement rolled back if the model creation fails.

To achieve this, you can use one of the following syntaxes. (Note: You should NOT use this syntax if using a database where dbt does not use transactions by default, including Snowflake, BigQuery, and Spark/Databricks.)
To achieve this behavior, you can use one of the following syntaxes. (Important Note: Do not use this syntax if you are using a database where dbt does not use transactions by default. This includes databases like Snowflake, BigQuery, and Spark/Databricks.)
mirnawong1 marked this conversation as resolved.
Show resolved Hide resolved

<Tabs>
<TabItem value="beforebegin" label="'before_begin' and 'after_commit'">
mirnawong1 marked this conversation as resolved.
Show resolved Hide resolved

#### Config block: use the `before_begin` and `after_commit` helper macros

Expand All @@ -200,6 +203,9 @@ select ...
```

</File>
</TabItem>

<TabItem value="dictionary" label="dictionary'">

#### Config block: use a dictionary
<File name='models/<modelname>.sql'>
Expand All @@ -224,6 +230,10 @@ select ...

</File>

</TabItem>

<TabItem value="dbt_project.yml" label="dbt_project.yml'">

#### `dbt_project.yml`: Use a dictionary

<File name='dbt_project.yml'>
Expand All @@ -242,3 +252,4 @@ models:
```

</File>
</TabItem>
Loading