dbt compile generates executable SQL from source
analysis files. You can find these compiled SQL files in the
target/ directory of your dbt project.
compile command is useful for:
- Visually inspecting the compiled output of model files. This is useful for validating complex jinja logic or macro usage.
- Manually running compiled SQL. While debugging a model or schema test, it's often useful to execute the underlying
selectstatement to find the source of the bug.
analysisfiles. Read more about analysis files here.
Some common misconceptions:
dbt compileis 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
The command accesses the data platform to cache-related metadata, and to run introspective queries. Use the flags:
--no-populate-cacheto 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
dbtflag, which means you need to add
dbtas a prefix. For example:
--no-introspectto disable introspective queries. dbt will raise an error if a model's definition requires running one. This is a
dbt compileflag, which means you need to add
dbt compileas a prefix. For example:
dbt compile --no-introspect.