Skip to content

Commit

Permalink
update cast_timestamp_to_iso8601 to work with timestamp and string (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rachellougee authored Feb 12, 2025
1 parent 7e39784 commit 4247bb3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/ol_dbt/macros/cast_timestamp_to_iso8601.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{% macro cast_timestamp_to_iso8601(column_name) %}
to_iso8601(from_iso8601_timestamp({{ column_name }}))
case
-- If the column is already a timestamp, convert to ISO 8601
when try_cast({{ column_name }} AS timestamp) is not null
then to_iso8601(try_cast({{ column_name }} AS timestamp))
-- otherwise, convert to ISO 8601 from a string
else to_iso8601(from_iso8601_timestamp(try_cast({{ column_name }} AS varchar)))
end
{% endmacro %}

0 comments on commit 4247bb3

Please sign in to comment.