forked from calogica/dbt-date
-
Notifications
You must be signed in to change notification settings - Fork 0
/
day_name.sql
37 lines (32 loc) · 1.09 KB
/
day_name.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 day_name(date, short=True) -%}
{{ adapter.dispatch('day_name', 'dbt_date') (date, short) }}
{%- endmacro %}
{%- macro default__day_name(date, short) -%}
{%- set f = 'Dy' if short else 'Day' -%}
to_char({{ date }}, '{{ f }}')
{%- endmacro %}
{%- macro snowflake__day_name(date, short) -%}
{%- if short -%}
dayname({{ date }})
{%- else -%}
-- long version not implemented on Snowflake so we're doing it manually :/
case dayname({{ date }})
when 'Mon' then 'Monday'
when 'Tue' then 'Tuesday'
when 'Wed' then 'Wednesday'
when 'Thu' then 'Thursday'
when 'Fri' then 'Friday'
when 'Sat' then 'Saturday'
when 'Sun' then 'Sunday'
end
{%- endif -%}
{%- endmacro %}
{%- macro bigquery__day_name(date, short) -%}
{%- set f = '%a' if short else '%A' -%}
format_date('{{ f }}', cast({{ date }} as date))
{%- endmacro %}
{%- macro postgres__day_name(date, short) -%}
{# FM = Fill mode, which suppresses padding blanks #}
{%- set f = 'FMDy' if short else 'FMDay' -%}
to_char({{ date }}, '{{ f }}')
{%- endmacro %}