diff --git a/website/docs/reference/dbt-jinja-functions/statement-blocks.md b/website/docs/reference/dbt-jinja-functions/statement-blocks.md index 2829ad3fe14..a5e40b1a7f0 100644 --- a/website/docs/reference/dbt-jinja-functions/statement-blocks.md +++ b/website/docs/reference/dbt-jinja-functions/statement-blocks.md @@ -16,6 +16,8 @@ We recommend using the [`run_query` macro](/reference/dbt-jinja-functions/run_qu ```sql +-- depends_on: {{ ref('users') }} + {%- call statement('states', fetch_result=True) -%} select distinct state from {{ ref('users') }} @@ -31,6 +33,42 @@ 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. If you are already `ref`ing the model outside of the statement block, the dependency will be automatically inferred, but otherwise you will need to [force the dependency](/reference/dbt-jinja-functions/ref#forcing-dependencies) with `-- depends_on`. + + + +```sql +-- depends_on: {{ ref('users') }} + +{% call statement('states', fetch_result=True) -%} + + select distinct state from {{ ref('users') }} + + /* + The unique states are: {{ load_result('states')['data'] }} + */ +{%- endcall %} +``` + + + + +```sql + +{% call statement('states', fetch_result=True) -%} + + select distinct state from {{ ref('users') }} + + /* + The unique states are: {{ load_result('states')['data'] }} + */ + +{%- endcall %} + +select id * 2 from {{ ref('users') }} +``` + + __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