diff --git a/website/docs/reference/dbt-jinja-functions/execute.md b/website/docs/reference/dbt-jinja-functions/execute.md index 05dd26a8ecf..f99bfa64734 100644 --- a/website/docs/reference/dbt-jinja-functions/execute.md +++ b/website/docs/reference/dbt-jinja-functions/execute.md @@ -17,17 +17,17 @@ Any Jinja that relies on a result being returned from the database will error du ```sql -{% set payment_method_query %} -select distinct -payment_method -from {{ ref('raw_payments') }} -order by 1 -{% endset %} - -{% set results = run_query(payment_method_query) %} - -{# Return the first column #} -{% set payment_methods = results.columns[0].values() %} +1 {% set payment_method_query %} +2 select distinct +3 payment_method +4 from {{ ref('raw_payments') }} +5 order by 1 +6 {% endset %} +7 +8 {% set results = run_query(payment_method_query) %} +9 +10 {# Return the first column #} +11 {% set payment_methods = results.columns[0].values() %} ``` @@ -40,7 +40,7 @@ Compilation Error in model order_payment_methods (models/order_payment_methods.s 'None' has no attribute 'table' ``` -This is because Line #11 assumes that a has been returned, when, during the parse phase, this query hasn't been run. +This is because line #11 in the earlier code example (`{% set payment_methods = results.columns[0].values() %}`) assumes that a has been returned, when, during the parse phase, this query hasn't been run. To work around this, wrap any problematic Jinja in an `{% if execute %}` statement: @@ -55,7 +55,6 @@ order by 1 {% endset %} {% set results = run_query(payment_method_query) %} - {% if execute %} {# Return the first column #} {% set payment_methods = results.columns[0].values() %}