Skip to content

Commit

Permalink
[Fix] Postgres-specific cents_to_dollars macro (#37)
Browse files Browse the repository at this point in the history
Postgres needs a little bit of special sauce to properly pad zeros to 2
decimals in the `cents_to_dollars` macro.
  • Loading branch information
gwenwindflower authored Apr 18, 2024
2 parents c708c01 + 13f0b77 commit 375683a
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions macros/cents_to_dollars.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
({{ column_name }} / 100)::numeric(16, 2)
{%- endmacro %}

{% macro postgres__cents_to_dollars(column_name) -%}
({{ column_name }}::numeric(16, 2) / 100)
{%- endmacro %}

{% macro bigquery__cents_to_dollars(column_name) %}
round(cast(({{ column_name }} / 100) as numeric), 2)
{% endmacro %}

0 comments on commit 375683a

Please sign in to comment.