Skip to content

Commit

Permalink
feat: update function to include 'contains range' edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
dleard committed Nov 27, 2020
1 parent e87541b commit 64099c4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion schema/deploy/trigger_functions/protect_date_overlap.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ begin;
loop
if (new.reporting_year != temp_row.reporting_year) then
if ((new.reporting_period_start between temp_row.reporting_period_start and temp_row.reporting_period_end)
or (temp_row.reporting_period_start between new.reporting_period_start and new.reporting_period_end)
or (new.reporting_period_end between temp_row.reporting_period_start and temp_row.reporting_period_end)
or (temp_row.reporting_period_end between new.reporting_period_start and new.reporting_period_end)
or (new.application_open_time between temp_row.application_open_time and temp_row.application_close_time)
or (new.application_close_time between temp_row.application_open_time and temp_row.application_close_time)) then
or (temp_row.application_open_time between new.application_open_time and new.application_close_time)
or (new.application_close_time between temp_row.application_open_time and temp_row.application_close_time)
or (temp_row.application_close_time between new.application_open_time and new.application_close_time))
then
raise exception 'New date range entry overlaps with date range for reporting year %', temp_row.reporting_year;
end if;
end if;
Expand Down

0 comments on commit 64099c4

Please sign in to comment.