MetricSign
EN|NLRequest Access
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

  1. 1Run `dbt compile --select <model_name>` and inspect the compiled SQL in `target/compiled/` — check if the file is empty or contains comments.
  2. 2Add `{{ log(some_variable, info=True) }}` statements to debug Jinja variable values during compilation.
  3. 3Review all {% if %} blocks in the model — add an {% else %} with a fallback query or raise an explicit error if no condition matches.
  4. 4If the issue is in a macro, test the macro in isolation with `dbt run-operation <macro_name>`.
  5. 5Check that environment variables used in Jinja conditions are set correctly in the target environment.

Frequently asked questions

Where can I see the compiled SQL that dbt tried to run?

After running `dbt compile`, check the `target/compiled/<project_name>/<path_to_model>.sql` file. For dbt Cloud, the compiled SQL is shown in the run details for each model.

Official documentation: dbt-docs

Other dbt errors