Skip to content

Commit

Permalink
Update cast_date_to_iso8601 to handle date and string (#1488)
Browse files Browse the repository at this point in the history
* update cast_date_to_iso8601 to handle date and string

* add comments per gemini-code-assist feedback
  • Loading branch information
rachellougee authored Feb 26, 2025
1 parent c9f04c2 commit f278499
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ol_dbt/macros/cast_date_to_iso8601.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{% macro cast_date_to_iso8601(column_name) %}
to_iso8601(from_iso8601_date({{ column_name }}))
case
when try_cast({{ column_name }} AS date) is not null -- Use try_cast to check if the column is already a date
then to_iso8601(try_cast({{ column_name }} AS date))

else to_iso8601(from_iso8601_date(try_cast({{ column_name }} AS varchar))) -- Convert to ISO 8601 from a string
end
{% endmacro %}

0 comments on commit f278499

Please sign in to comment.