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?.
CREATE TABLE
ALTER TABLE
INSERT 0 2
INSERT 0 2
ERROR: conflicting key value violates exclusion constraint "name_and_type_within_6_months" DETAIL: Key (name, type, tsrange(date, date + '6 mons'::interval))=(jane, job, ["2020-07-02 00:00:00","2021-01-02 00:00:00")) conflicts with existing key (name, type, tsrange(date, date + '6 mons'::interval))=(jane, job, ["2020-03-01 00:00:00","2020-09-01 00:00:00")).
id | date | name | type |
---|---|---|---|
1 | 2020-01-01 00:00:00 | bob | job |
2 | 2020-03-01 00:00:00 | jane | job |
3 | 2020-09-02 00:00:00 | jane | job |
4 | 2020-07-02 00:00:00 | bob | job |
SELECT 4