Skip to content

Commit bb21058

Browse files
seunghanhongclrcrl
authored andcommitted
Support quarter in postgres last day (#333)
1 parent 8b843f2 commit bb21058

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
* Add new schema test, `not_accepted_values` ([#284](https://github.com/fishtown-analytics/dbt-utils/pull/284) [@JavierMonton](https://github.com/JavierMonton))
66
* Support a new argument, `zero_length_range_allowed` in the `mutually_exclusive_ranges` test ([#307](https://github.com/fishtown-analytics/dbt-utils/pull/307) [@zemekeng](https://github.com/zemekeneng))
77
* Add new schema test, `sequential_values` ([#318](https://github.com/fishtown-analytics/dbt-utils/pull/318), inspired by [@hundredwatt](https://github.com/hundredwatt))
8+
* Support `quarter` in the `postgres__last_day` macro ([#333](https://github.com/fishtown-analytics/dbt-utils/pull/333/files), [@seunghanhong](https://github.com/seunghanhong))
89

910

1011
## Fixes
1112
* Handle booleans gracefully in the unpivot macro ([#305](https://github.com/fishtown-analytics/dbt-utils/pull/305) [@avishalom](https://github.com/avishalom))
1213
* Fix a bug in `get_relation_by_prefix` that happens with Snowflake external tables. Now the macro will retrieve tables that match the prefix which are external tables ([#350](https://github.com/fishtown-analytics/dbt-utils/issues/350))
14+
1315
## Under the hood
1416

1517

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
date_day,date_part,result
22
2018-01-02,month,2018-01-31
3+
2018-01-02,quarter,2018-03-31
34
2018-01-02,year,2018-12-31
45
,month,

integration_tests/models/cross_db_utils/test_last_day.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ with data as (
88
select
99
case
1010
when date_part = 'month' then {{ dbt_utils.last_day('date_day', 'month') }}
11+
when date_part = 'quarter' then {{ dbt_utils.last_day('date_day', 'quarter') }}
1112
when date_part = 'year' then {{ dbt_utils.last_day('date_day', 'year') }}
1213
else null
1314
end as actual,

macros/cross_db_utils/last_day.sql

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ testing is required to validate that it will work on other dateparts.
2525
{% macro postgres__last_day(date, datepart) -%}
2626

2727
{%- if datepart == 'quarter' -%}
28-
{{ exceptions.raise_compiler_error(
29-
"dbt_utils.last_day is not supported for datepart 'quarter' on this adapter") }}
28+
-- postgres dateadd does not support quarter interval.
29+
cast(
30+
{{dbt_utils.dateadd('day', '-1',
31+
dbt_utils.dateadd('month', '3', dbt_utils.date_trunc(datepart, date))
32+
)}}
33+
as date)
3034
{%- else -%}
3135
{{dbt_utils.default_last_day(date, datepart)}}
3236
{%- endif -%}

0 commit comments

Comments
 (0)