-
Notifications
You must be signed in to change notification settings - Fork 503
/
dateadd.sql
37 lines (23 loc) · 1 KB
/
dateadd.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{% macro dateadd(datepart, interval, from_date_or_timestamp) %}
{{ return(adapter.dispatch('dateadd', 'dbt_utils')(datepart, interval, from_date_or_timestamp)) }}
{% endmacro %}
{% macro default__dateadd(datepart, interval, from_date_or_timestamp) %}
dateadd(
{{ datepart }},
{{ interval }},
{{ from_date_or_timestamp }}
)
{% endmacro %}
{% macro bigquery__dateadd(datepart, interval, from_date_or_timestamp) %}
datetime_add(
cast( {{ from_date_or_timestamp }} as datetime),
interval {{ interval }} {{ datepart }}
)
{% endmacro %}
{% macro postgres__dateadd(datepart, interval, from_date_or_timestamp) %}
{{ from_date_or_timestamp }} + ((interval '1 {{ datepart }}') * ({{ interval }}))
{% endmacro %}
{# redshift should use default instead of postgres #}
{% macro redshift__dateadd(datepart, interval, from_date_or_timestamp) %}
{{ return(dbt_utils.default__dateadd(datepart, interval, from_date_or_timestamp)) }}
{% endmacro %}