Fix error unsetting season range that corresponds to existing range

This commit is contained in:
jordi fita mas 2023-09-28 02:28:33 +02:00
parent 2d209c8128
commit 50cc4c41b3
2 changed files with 8 additions and 3 deletions

View File

@ -13,6 +13,8 @@ declare
tmp_range daterange;
tmp_id integer;
begin
delete from season_calendar where range @> season_range;
for tmp_id, tmp_range in
select season_id, season_range
from season_calendar
@ -25,8 +27,6 @@ begin
;
end loop;
delete from season_calendar where range @> season_range;
update season_calendar
set season_range = season_range - range
where season_range && range

View File

@ -5,7 +5,7 @@ reset client_min_messages;
begin;
select plan(14);
select plan(15);
set search_path to camper, public;
@ -47,12 +47,17 @@ values ( 9, '[2023-04-01, 2023-04-05]')
, (10, '[2023-04-20, 2023-04-22]')
, ( 9, '[2023-04-23, 2023-04-27]')
, ( 8, '[2023-04-28, 2023-04-30]')
, ( 7, '[2023-05-01, 2023-05-31]')
;
select lives_ok($$ select unset_season_range('[2023-04-08, 2023-04-11]') $$);
select lives_ok($$ select unset_season_range('[2023-04-15, 2023-04-15]') $$);
select lives_ok($$ select unset_season_range('[2023-04-20, 2023-04-23]') $$);
select lives_ok($$ select unset_season_range('[2023-04-26, 2023-04-29]') $$);
select lives_ok(
$$ select unset_season_range('[2023-05-01, 2023-05-31]') $$,
'Should work if the range to unset is exactly the same as an existing range'
);
select bag_eq(
$$ select season_id, season_range from season_calendar $$,