forked from calogica/dbt-date
-
Notifications
You must be signed in to change notification settings - Fork 0
/
from_unixtimestamp.sql
55 lines (50 loc) · 1.76 KB
/
from_unixtimestamp.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 from_unixtimestamp(epochs, format="seconds") -%}
{{ adapter.dispatch('from_unixtimestamp', 'dbt_date') (epochs, format) }}
{%- endmacro %}
{%- macro default__from_unixtimestamp(epochs, format="seconds") -%}
{%- if format != "seconds" -%}
{{ exceptions.raise_compiler_error(
"value " ~ format ~ " for `format` for from_unixtimestamp is not supported."
)
}}
{% endif -%}
to_timestamp({{ epochs }})
{%- endmacro %}
{%- macro postgres__from_unixtimestamp(epochs, format="seconds") -%}
{%- if format != "seconds" -%}
{{ exceptions.raise_compiler_error(
"value " ~ format ~ " for `format` for from_unixtimestamp is not supported."
)
}}
{% endif -%}
cast(to_timestamp({{ epochs }}) at time zone 'UTC' as timestamp)
{%- endmacro %}
{%- macro snowflake__from_unixtimestamp(epochs, format) -%}
{%- if format == "seconds" -%}
{%- set scale = 0 -%}
{%- elif format == "milliseconds" -%}
{%- set scale = 3 -%}
{%- elif format == "microseconds" -%}
{%- set scale = 6 -%}
{%- else -%}
{{ exceptions.raise_compiler_error(
"value " ~ format ~ " for `format` for from_unixtimestamp is not supported."
)
}}
{% endif -%}
to_timestamp_ntz({{ epochs }}, {{ scale }})
{%- endmacro %}
{%- macro bigquery__from_unixtimestamp(epochs, format) -%}
{%- if format == "seconds" -%}
timestamp_seconds({{ epochs }})
{%- elif format == "milliseconds" -%}
timestamp_millis({{ epochs }})
{%- elif format == "microseconds" -%}
timestamp_micros({{ epochs }})
{%- else -%}
{{ exceptions.raise_compiler_error(
"value " ~ format ~ " for `format` for from_unixtimestamp is not supported."
)
}}
{% endif -%}
{%- endmacro %}