2024-10-02 14:50:34 +02:00
|
|
|
/*
|
|
|
|
|
This macro converts a timestamp column from Unix epoch time (in milliseconds)
|
|
|
|
|
to a UTC timestamp and a corresponding UTC date.
|
|
|
|
|
|
|
|
|
|
It generates two output fields:
|
|
|
|
|
1. The timestamp in UTC, with the alias formatted as <column_name>_at_utc.
|
|
|
|
|
2. The date in UTC, with the alias formatted as <column_name>_date_utc.
|
|
|
|
|
|
|
|
|
|
This macro is intended to be used within a SELECT statement
|
|
|
|
|
and ensures that the output is properly formatted for further analysis.
|
|
|
|
|
*/
|
|
|
|
|
{% macro timestamp_to_utc(column_name) %}
|
|
|
|
|
to_timestamp(
|
|
|
|
|
{{ adapter.quote(column_name) }}::double precision / 1000
|
2024-10-03 12:19:27 +02:00
|
|
|
) at time zone 'UTC'
|
|
|
|
|
as {{ column_name | replace("At", "") | replace("Date", "") }}_at_utc,
|
2024-10-02 14:50:34 +02:00
|
|
|
|
|
|
|
|
cast(
|
|
|
|
|
to_timestamp(
|
|
|
|
|
{{ adapter.quote(column_name) }}::double precision / 1000
|
|
|
|
|
) at time zone 'UTC' as date
|
2024-10-03 12:19:27 +02:00
|
|
|
) as {{ column_name | replace("At", "") | replace("Date", "") }}_date_utc
|
2024-10-02 14:50:34 +02:00
|
|
|
{% endmacro %}
|