From a115cd0ca78681b87017854942aa5685fbe26942 Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Fri, 22 Mar 2024 13:41:50 +0000 Subject: [PATCH 1/5] add code examples --- .../dbt-jinja-functions/statement-blocks.md | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/website/docs/reference/dbt-jinja-functions/statement-blocks.md b/website/docs/reference/dbt-jinja-functions/statement-blocks.md index 2829ad3fe14..0ce865eb9da 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,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 an explicitly specify it using `-- depends_on` or doing a `ref()` function outside the statement block ensure proper execution. + + + +```sql +-- depends_on: {{ ref('users') }} + +{%- call statement('states', fetch_result=True) -%} + + select distinct state from {{ ref('users') }} + +{%- endcall -%} +``` + + + + +```sql + +{%- call statement('states', fetch_result=True) -%} + + select distinct state from {{ ref('users') }} + +{%- 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 From 858ae2f2e5eb4677caf6f131bffcdb7a14f84b96 Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Mon, 25 Mar 2024 10:13:43 +0000 Subject: [PATCH 2/5] Update website/docs/reference/dbt-jinja-functions/statement-blocks.md --- website/docs/reference/dbt-jinja-functions/statement-blocks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/reference/dbt-jinja-functions/statement-blocks.md b/website/docs/reference/dbt-jinja-functions/statement-blocks.md index 0ce865eb9da..cf0292caaf9 100644 --- a/website/docs/reference/dbt-jinja-functions/statement-blocks.md +++ b/website/docs/reference/dbt-jinja-functions/statement-blocks.md @@ -33,7 +33,7 @@ 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 an explicitly specify it using `-- depends_on` or doing a `ref()` function outside the statement block ensure proper execution. +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. From a7edb347448dbb1acda5be9784fd4b10a0216b17 Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Wed, 27 Mar 2024 11:10:05 +0000 Subject: [PATCH 3/5] Update website/docs/reference/dbt-jinja-functions/statement-blocks.md Co-authored-by: Joel Labes --- .../reference/dbt-jinja-functions/statement-blocks.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/website/docs/reference/dbt-jinja-functions/statement-blocks.md b/website/docs/reference/dbt-jinja-functions/statement-blocks.md index cf0292caaf9..ddb404e6685 100644 --- a/website/docs/reference/dbt-jinja-functions/statement-blocks.md +++ b/website/docs/reference/dbt-jinja-functions/statement-blocks.md @@ -52,11 +52,15 @@ When executing a `statement`, dbt needs to understand how to resolve references ```sql -{%- call statement('states', fetch_result=True) -%} +{% call statement('states', fetch_result=True) -%} select distinct state from {{ ref('users') }} -{%- endcall -%} + /* + The unique states are: {{ load_result('states')['data'] }} + */ + +{%- endcall %} select id * 2 from {{ ref('users') }} ``` From 9637f8fe71d589d57ec3a52f1cee6fb886c389a8 Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Wed, 27 Mar 2024 11:10:26 +0000 Subject: [PATCH 4/5] Update website/docs/reference/dbt-jinja-functions/statement-blocks.md Co-authored-by: Joel Labes --- .../docs/reference/dbt-jinja-functions/statement-blocks.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/website/docs/reference/dbt-jinja-functions/statement-blocks.md b/website/docs/reference/dbt-jinja-functions/statement-blocks.md index ddb404e6685..bdf51dc9d82 100644 --- a/website/docs/reference/dbt-jinja-functions/statement-blocks.md +++ b/website/docs/reference/dbt-jinja-functions/statement-blocks.md @@ -40,11 +40,14 @@ When executing a `statement`, dbt needs to understand how to resolve references ```sql -- depends_on: {{ ref('users') }} -{%- call statement('states', fetch_result=True) -%} +{% call statement('states', fetch_result=True) -%} select distinct state from {{ ref('users') }} -{%- endcall -%} + /* + The unique states are: {{ load_result('states')['data'] }} + */ +{%- endcall %} ``` From dffd4617786bfefe51e436c040a381ae3d6d2da3 Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Wed, 27 Mar 2024 11:10:54 +0000 Subject: [PATCH 5/5] Update website/docs/reference/dbt-jinja-functions/statement-blocks.md Co-authored-by: Joel Labes --- website/docs/reference/dbt-jinja-functions/statement-blocks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/reference/dbt-jinja-functions/statement-blocks.md b/website/docs/reference/dbt-jinja-functions/statement-blocks.md index bdf51dc9d82..a5e40b1a7f0 100644 --- a/website/docs/reference/dbt-jinja-functions/statement-blocks.md +++ b/website/docs/reference/dbt-jinja-functions/statement-blocks.md @@ -33,7 +33,7 @@ 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. +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`.