forked from calogica/dbt-date
-
Notifications
You must be signed in to change notification settings - Fork 0
/
day_name.sql
55 lines (47 loc) · 1.53 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{%- 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 %}
{%- macro duckdb__day_name(date, short) -%}
{%- if short -%}
substr(dayname({{ date }}), 1, 3)
{%- else -%}
dayname({{ date }})
{%- endif -%}
{%- endmacro %}
{%- macro spark__day_name(date, short) -%}
{%- set f = 'E' if short else 'EEEE' -%}
date_format({{ date }}, '{{ f }}')
{%- endmacro %}
{%- macro trino__day_name(date, short) -%}
{%- set f = 'a' if short else 'W' -%}
date_format({{ date }}, '%{{ f }}')
{%- endmacro %}