duckdb / dbt-duckdb

dbt (http://getdbt.com) adapter for DuckDB (http://duckdb.org)
Apache License 2.0
935 stars 89 forks source link

Duck Db support of DATEADD from Core #405

Open alittlesliceoftom opened 5 months ago

alittlesliceoftom commented 5 months ago

I tried the example here: https://docs.getdbt.com/sql-reference/dateadd

SELECT {{ dateadd(datepart="month", interval=1, from_date_or_timestamp="'2021-08-12'") }}

This fails.

I tweaked and this works:

SELECT {{ dateadd(datepart="month", interval=1, from_date_or_timestamp="DATE '2021-08-12'") }}  AS period_of_load

In general I think adapters should support the documented case from core.

Here duckdb seems to want date strings to be explicitly refererred to as dates in addition operations as per: https://duckdb.org/docs/sql/functions/date.html

As such I suggest that : https://github.com/duckdb/dbt-duckdb/blob/master/dbt/include/duckdb/macros/utils/dateadd.sql

Is updated to include: DATE at start

alittlesliceoftom commented 5 months ago

Context, I'm trying to complete this issue: https://github.com/alittlesliceoftom/insert_by_timeperiod/issues/2 on the insert by timeperiod repo, and struggling here with duck db compatability.