---
title: "About dbt compile command"
source: dbt Core Documentation
source_url: https://github.com/dbt-labs/docs.getdbt.com
licence: Apache-2.0
domain: data-and-analysis
subdomain: dbt-docs
date_added: 2026-04-25
---

`dbt compile` generates executable SQL from source files for:

<VersionBlock lastVersion="1.11">
- [Models](/docs/build/models)
- [Data tests](/docs/build/data-tests)
- [Analyses](/docs/build/analyses)
- [Functions](/docs/build/udfs)
</VersionBlock>
<VersionBlock firstVersion="1.12">
- [Models](/docs/build/models)
- [Data tests](/docs/build/data-tests)
- [Analyses](/docs/build/analyses)
- [Functions](/docs/build/udfs)
- [Snapshots](/docs/build/snapshots) (available in <Constant name="core" /> v1.12)
</VersionBlock>

You can find these compiled SQL files in the `target/` directory of your dbt project.

The `compile` command is useful for:

- Visually inspecting the compiled output of resource files. This is useful for validating complex Jinja logic or macro usage.
- Manually running compiled SQL. While debugging a model or [data test](/docs/build/data-tests), it's often useful to execute the underlying `select` statement to find the source of the bug.
- Compiling `analysis` files. Read more about analysis files [here](/docs/build/analyses).

Some common misconceptions:
- `dbt compile` is _not_ a pre-requisite of `dbt run`, or other building commands. Those commands will handle compilation themselves.
- If you just want dbt to read and validate your project code, without connecting to the data warehouse, use `dbt parse` instead.

### Interactive compile

Starting in dbt v1.5, `compile` can be "interactive" in the CLI, by displaying the compiled code of a node or arbitrary dbt-SQL query:
- `--select` a specific node _by name_
- `--inline` an arbitrary dbt-SQL query

This will log the compiled SQL to the terminal, in addition to writing to the `target/` directory.

For example:

```bash
dbt compile --select "stg_orders"                           
dbt compile --inline "select * from {{ ref('raw_orders') }}"
```

returns the following:

```bash
dbt compile --select "stg_orders"                           

21:17:09  Running with dbt=1.7.5
21:17:09  Registered adapter: postgres=1.7.5
21:17:09  Found 5 models, 3 seeds, 20 tests, 0 sources, 0 exposures, 0 metrics, 401 macros, 0 groups, 0 semantic models
21:17:09  
21:17:09 Concurrency: 24 threads (target='dev')
21:17:09  
21:17:09  Compiled node 'stg_orders' is:
with source as (
    select * from "jaffle_shop"."main"."raw_orders"

),

renamed as (

    select
        id as order_id,
        user_id as customer_id,
        order_date,
        status

    from source

)

select * from renamed
```

```bash
dbt compile --inline "select * from {{ ref('raw_orders') }}"

18:15:49  Running with dbt=1.7.5
18:15:50  Registered adapter: postgres=1.7.5
18:15:50  Found 5 models, 3 seeds, 20 tests, 0 sources, 0 exposures, 0 metrics, 401 macros, 0 groups, 0 semantic models
18:15:50  
18:15:50  Concurrency: 5 threads (target='postgres')
18:15:50  
18:15:50  Compiled inline node is:
select * from "jaffle_shop"."main"."raw_orders"
```

The command accesses the data platform to cache-related metadata, and to run introspective queries. Use the flags:
- `--no-populate-cache` to disable the initial cache population. If metadata is needed, it will be a cache miss, requiring dbt to run the metadata query. This is a `dbt` flag, which means you need to add `dbt` as a prefix. For example: `dbt --no-populate-cache`.
- `--no-introspect` to disable [introspective queries](/faqs/Warehouse/db-connection-dbt-compile#introspective-queries). dbt will raise an error if a resource's definition requires running one. This is a `dbt compile` flag, which means you need to add `dbt compile` as a prefix. For example:`dbt compile --no-introspect`.

:::caution Resources that use introspective queries
Compiled SQL for resources that use introspective queries may depend on metadata from your warehouse. Compilation may be incomplete or may differ depending on the state of that metadata.
:::

### FAQs
<FAQ path="Warehouse/db-connection-dbt-compile" />
