I am trying to use the dbt_utils.date_spine macro :
select
{{ dbt_utils.date_spine(datepart="day", start_date="cast('2019-01-01' as date)", end_date="cast('2020-01-01' as date)") }} as purchase_date
from table(generator(rowcount=>10))
And get the following error :
Database Error in model purchase (models/data_generation/purchase.sql)
001003 (42000): SQL compilation error:
syntax error line 21 at position 0 unexpected 'with'.
syntax error line 29 at position 5 unexpected ','.
compiled SQL at target........purchase.sql
Has anyone seen this before?
I'm afraid that's not the right way to use/call this macro.
One of the most common options is to materialize a table somewhere and then have other models referencing that table. You can think about that as a
Calendar Tableor if you want to go further down you can build your ownDate Dimension.For example, let's say you have a
calendar_tablemodel defined as:Once built the model in the data warehouse, then you can reference it in other models, like:
You can also materialize the calendar_table model as
ephemeralin case you don't want to build it in the DW.But in case you don't want to have a separate model for that, then you can use with a CTE, for example:
Here are some related posts from dbt discourse:
https://discourse.getdbt.com/t/date-dimensions/735
https://discourse.getdbt.com/t/building-a-calendar-table-using-dbt/325