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

Clarify statement blocks macro need ref #5138

Merged
merged 27 commits into from
Mar 28, 2024
Merged
Changes from 14 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a115cd0
add code examples
mirnawong1 Mar 22, 2024
e1907c3
Merge branch 'current' into statement-blocks
mirnawong1 Mar 25, 2024
858ae2f
Update website/docs/reference/dbt-jinja-functions/statement-blocks.md
mirnawong1 Mar 25, 2024
7250222
This branch was auto-updated!
github-actions[bot] Mar 25, 2024
430982e
This branch was auto-updated!
github-actions[bot] Mar 25, 2024
ca722c8
This branch was auto-updated!
github-actions[bot] Mar 25, 2024
56ada34
This branch was auto-updated!
github-actions[bot] Mar 26, 2024
f724d02
This branch was auto-updated!
github-actions[bot] Mar 26, 2024
30128df
This branch was auto-updated!
github-actions[bot] Mar 26, 2024
d49902a
This branch was auto-updated!
github-actions[bot] Mar 26, 2024
137aafb
This branch was auto-updated!
github-actions[bot] Mar 26, 2024
6ceda15
This branch was auto-updated!
github-actions[bot] Mar 26, 2024
2c7d693
This branch was auto-updated!
github-actions[bot] Mar 26, 2024
b8eddf6
This branch was auto-updated!
github-actions[bot] Mar 27, 2024
8626591
This branch was auto-updated!
github-actions[bot] Mar 27, 2024
4d5f216
This branch was auto-updated!
github-actions[bot] Mar 27, 2024
9f045d7
This branch was auto-updated!
github-actions[bot] Mar 27, 2024
a7edb34
Update website/docs/reference/dbt-jinja-functions/statement-blocks.md
mirnawong1 Mar 27, 2024
9637f8f
Update website/docs/reference/dbt-jinja-functions/statement-blocks.md
mirnawong1 Mar 27, 2024
dffd461
Update website/docs/reference/dbt-jinja-functions/statement-blocks.md
mirnawong1 Mar 27, 2024
cda0258
This branch was auto-updated!
github-actions[bot] Mar 27, 2024
95b0b88
This branch was auto-updated!
github-actions[bot] Mar 27, 2024
46ca3a3
This branch was auto-updated!
github-actions[bot] Mar 27, 2024
080a039
This branch was auto-updated!
github-actions[bot] Mar 27, 2024
10c9222
This branch was auto-updated!
github-actions[bot] Mar 27, 2024
0d2d286
This branch was auto-updated!
github-actions[bot] Mar 27, 2024
256cb73
This branch was auto-updated!
github-actions[bot] Mar 27, 2024
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
31 changes: 31 additions & 0 deletions website/docs/reference/dbt-jinja-functions/statement-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ We recommend using the [`run_query` macro](/reference/dbt-jinja-functions/run_qu
<File name='get_states_statement.sql'>

```sql
-- depends_on: {{ ref('users') }}

{%- call statement('states', fetch_result=True) -%}

select distinct state from {{ ref('users') }}
Expand All @@ -31,6 +33,35 @@ The signature of the `statement` block looks like this:
statement(name=None, fetch_result=False, auto_begin=True)
```

When executing a `statement`, dbt needs to understand how to resolve references to other dbt models or resources. You can explicitly specify it using `-- depends_on` or doing a `ref()` function outside the statement block to ensure proper execution.
mirnawong1 marked this conversation as resolved.
Show resolved Hide resolved

<expandable alt_header="Example using -- depends_on">

```sql
-- depends_on: {{ ref('users') }}

{%- call statement('states', fetch_result=True) -%}

select distinct state from {{ ref('users') }}

{%- endcall -%}
mirnawong1 marked this conversation as resolved.
Show resolved Hide resolved
```
</expandable>

<expandable alt_header="Example using ref() function">

```sql

{%- call statement('states', fetch_result=True) -%}

select distinct state from {{ ref('users') }}

{%- endcall -%}
mirnawong1 marked this conversation as resolved.
Show resolved Hide resolved

select id * 2 from {{ ref('users') }}
```
</expandable>

__Args__:
- `name` (string): The name for the result set returned by this statement
- `fetch_result` (bool): If True, load the results of the statement into the Jinja context
Expand Down
Loading