How to inject additional SQL to DDL statement DBT uses?

Hello!

Is there way to inject additional SQL clause to DDL statement DBT uses for table creation in a less painful way?

I want to use partitioned tables in Postgres with DBT and the clause that I need to inject is this one:

CREATE TABLE measurement (
    city_id         int not null,
    logdate         date not null,
    peaktemp        int,
    unitsales       int
) **PARTITION BY RANGE (logdate)**;

Can you please point me to the right direction on how it can be done (for example, using custom materialization)?

How about creating the table by yourself on Postgres thereby creating the partitions with your code. I think DBT will run a create TABLE IF NOT EXISTS against your DB.

Indeed. This is one of the options.

1 Like