By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Help with an interesting Postgres question: Why isn't an Index Only Scan used on a partition accessed via the parent table?.
version |
---|
PostgreSQL 11.1 (Debian 11.1-1.pgdg90+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit |
1 rows affected
ERROR: duplicate key value violates unique constraint "date_regular_ranges_uq"
DETAIL: Key (user_id, start_at, end_at)=(1, 2019-03-01, 2019-03-05) already exists.
1 rows affected
1 rows affected
1 rows affected
1 rows affected
ERROR: conflicting key value violates exclusion constraint "date_exception_ranges_bounds"
DETAIL: Key (user_id, (is_exception::integer), daterange(start_at, end_at, '[]'::text))=(1, 1, [2019-03-02,2019-03-04)) conflicts with existing key (user_id, (is_exception::integer), daterange(start_at, end_at, '[]'::text))=(1, 1, [2019-03-02,2019-03-04)).
ERROR: conflicting key value violates exclusion constraint "date_exception_ranges_bounds"
DETAIL: Key (user_id, (is_exception::integer), daterange(start_at, end_at, '[]'::text))=(1, 0, [2019-03-03,2019-03-04)) conflicts with existing key (user_id, (is_exception::integer), daterange(start_at, end_at, '[]'::text))=(1, 0, [2019-03-03,2019-03-04)).
ERROR: new row for relation "date_exception_ranges" violates check constraint "date_exception_ranges_ck"
DETAIL: Failing row contains (7, 1, 2019-03-15, 2019-03-15, 2019-03-01, 2019-03-05, t).
ERROR: new row for relation "date_exception_ranges" violates check constraint "date_exception_ranges_ck"
DETAIL: Failing row contains (8, 1, 2019-03-10, 2019-03-10, 2019-03-01, 2019-03-05, f).
id | user_id | start_at | end_at |
---|---|---|---|
1 | 1 | 2019-03-01 | 2019-03-05 |
id | user_id | start_at | end_at | regular_start_at | regular_end_at | is_exception | is_day_off |
---|---|---|---|---|---|---|---|
1 | 1 | 2019-03-02 | 2019-03-03 | 2019-03-01 | 2019-03-05 | t | f |
2 | 1 | 2019-03-04 | 2019-03-04 | 2019-03-01 | 2019-03-05 | t | f |
3 | 1 | 2019-03-03 | 2019-03-03 | 2019-03-01 | 2019-03-05 | f | t |
4 | 1 | 2019-03-05 | 2019-03-05 | 2019-03-01 | 2019-03-05 | f | t |