-
Notifications
You must be signed in to change notification settings - Fork 1
/
datepart.sql
35 lines (26 loc) · 850 Bytes
/
datepart.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
{% macro datepart(column, part='day') %}
{{ adapter.dispatch('datepart', 'dbt_resto') (column, part) }}
{% endmacro %}
{% macro default__datepart(column, part) %}
date_part({{ part }}, {{ column }})
{% endmacro %}
{% macro sqlserver__datepart(column, part) %}
{%- set mapped_part = part -%}
{%- if part == 'dayofweek' -%}
{%- set mapped_part = 'weekday' -%}
{%- endif -%}
{%- if part == 'week' -%}
{%- set mapped_part = 'iso_week' -%}
{%- endif -%}
datepart({{ mapped_part }}, {{ column }})
{% endmacro %}
{% macro postgres__datepart(column, part) %}
{%- set mapped_part = part -%}
{%- if part == 'dayofweek' -%}
{%- set mapped_part = 'dow' -%}
{%- endif -%}
{%- if part == 'dayofyear' -%}
{%- set mapped_part = 'doy' -%}
{%- endif -%}
date_part('{{ mapped_part }}', {{ column }})
{% endmacro %}