Skip to content

Commit

Permalink
Add default and PG-specific versions for from_unixtimestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
clausherther committed Jun 14, 2021
1 parent 15e8d0b commit bc5a637
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions macros/calendar_date/from_unixtimestamp.sql
Expand Up @@ -2,8 +2,28 @@
{{ adapter.dispatch('from_unixtimestamp', packages = dbt_date._get_utils_namespaces()) (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" -%}
Expand All @@ -13,10 +33,10 @@
{%- else -%}
{{ exceptions.raise_compiler_error(
"value " ~ format ~ " for `format` for from_unixtimestamp is not supported."
)
)
}}
{% endif -%}

to_timestamp_ntz({{ epochs }}, {{ scale }})

{%- endmacro %}
Expand All @@ -31,7 +51,7 @@
{%- else -%}
{{ exceptions.raise_compiler_error(
"value " ~ format ~ " for `format` for from_unixtimestamp is not supported."
)
)
}}
{% endif -%}
{%- endmacro %}

0 comments on commit bc5a637

Please sign in to comment.