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 Table
or if you want to go further down you can build your own Date Dimension
.
For example, let's say you have a calendar_table
model defined as:
{{
config(
materialized = 'table',
)
}}
{{ dbt_utils.date_spine(
datepart="day",
start_date="to_date('01/01/2020', 'mm/dd/yyyy')",
end_date="to_date('01/01/2027', 'mm/dd/yyyy')"
)
}}
Once built the model in the data warehouse, then you can reference it in other models, like:
-- another_model.sql
select * from {{ ref('calendar_table') }}
You can also materialize the calendar_table model as ephemeral
in 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:
with date_spine as (
{{- dbt_utils.date_spine(
datepart="day",
start_date="to_date('01/01/2020', 'mm/dd/yyyy')",
end_date="to_date('01/01/2027', 'mm/dd/yyyy')"
)
-}}
)
, other_cte as (
...
)
...
Note that the code generated from the macro is not friendly to be used in a view
materialization. You might prefer to use table
for that.
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