Question 1 · Developing and Optimizing dbt Models
An analytics engineer writes the following Jinja macro in macros/limit_dev.sql:
{% macro dev_limit(n=100) %}
{% if target.name == 'dev' %}
LIMIT {{ n }}
{% endif %}
{% endmacro %}
A model then calls {{ dev_limit() }}. When this model is run against the prod target, what SQL will be produced for the LIMIT clause?
Show answer & explanation
Correct answer: C
- C. No LIMIT clause is added, because the
{% if %}block is false and nothing is rendered
When target.name is 'prod', the {% if target.name == 'dev' %} condition evaluates to false, so the block renders nothing — no LIMIT clause appears in the compiled SQL. A) is wrong — the default argument n=100 only matters if the block executes; since the condition is false, n is irrelevant. B) is wrong — dbt does not substitute a zero; it simply renders an empty string. D) is wrong — macros with conditional logic on target.name are a standard, supported dbt pattern.