-
-
Notifications
You must be signed in to change notification settings - Fork 65
/
from_unixtimestamp.sql
84 lines (75 loc) · 2.9 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{%- 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 %}
{%- macro trino__from_unixtimestamp(epochs, format) -%}
{%- if format == "seconds" -%}
cast(from_unixtime({{ epochs }}) AT TIME ZONE 'UTC' as {{ dbt.type_timestamp() }})
{%- elif format == "milliseconds" -%}
cast(from_unixtime_nanos({{ epochs }} * pow(10, 6)) AT TIME ZONE 'UTC' as {{ dbt.type_timestamp() }})
{%- elif format == "microseconds" -%}
cast(from_unixtime_nanos({{ epochs }} * pow(10, 3)) AT TIME ZONE 'UTC' as {{ dbt.type_timestamp() }})
{%- elif format == "nanoseconds" -%}
cast(from_unixtime_nanos({{ epochs }}) AT TIME ZONE 'UTC' as {{ dbt.type_timestamp() }})
{%- else -%}
{{ exceptions.raise_compiler_error(
"value " ~ format ~ " for `format` for from_unixtimestamp is not supported."
)
}}
{% endif -%}
{%- endmacro %}
{%- macro duckdb__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 %}