Search code examples
postgresqldbt

Add index to dbt model column?


We are considering using dbt to manage models in our PostgreSQL data warehouse. Since dbt models are SQL select statements, there doesn't seem to be an obvious, or documented, way to specify that a particular column should have an index.

How can we specify column indexes on dbt models?


Solution

  • From dbt docs:

    {{ config(
        materialized = 'table',
        indexes=[
          {'columns': ['column_a'], 'type': 'hash'},
          {'columns': ['column_a', 'column_b'], 'unique': True},
        ]
    )}}
    
    select ...