Medium severitydbt
Power BI Refresh Error:
Database Error: cannot run an empty query
What does this error mean?
dbt generated an empty SQL query that the database rejected — almost always a Jinja templating error, an empty macro expansion, or a model that conditionally renders no SQL.
Common causes
- 1A Jinja block ({% if %} / {% for %}) evaluates to False or iterates over an empty list, resulting in no SQL being rendered
- 2A macro called from the model returns an empty string under certain conditions
- 3A dbt_utils or custom macro has a bug where it produces no output for a specific input combination
- 4A model uses `{{ config(...) }}` blocks that consume most of the file and the actual SELECT is accidentally removed
- 5An environment variable used in a Jinja condition is not set, causing the condition to evaluate unexpectedly
How to fix it
- 1Run `dbt compile --select <model_name>` and inspect the compiled SQL in `target/compiled/` — check if the file is empty or contains comments.
- 2Add `{{ log(some_variable, info=True) }}` statements to debug Jinja variable values during compilation.
- 3Review all {% if %} blocks in the model — add an {% else %} with a fallback query or raise an explicit error if no condition matches.
- 4If the issue is in a macro, test the macro in isolation with `dbt run-operation <macro_name>`.
- 5Check that environment variables used in Jinja conditions are set correctly in the target environment.
Frequently asked questions
Official documentation: dbt-docs