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 release (
id serial PRIMARY KEY
, release_date date
);
INSERT INTO release (release_date) VALUES
('1994-05-30')
, ('1998-06-10')
, ('2010-06-30')
;
CREATE TABLE
INSERT 0 3
SELECT *
, (release_date + (date_trunc('year', LOCALTIMESTAMP)
- date_trunc('year', release_date)))::date - CURRENT_DATE AS days_till_aniversary
FROM release;
id | release_date | days_till_aniversary |
---|---|---|
1 | 1994-05-30 | -141 |
2 | 1998-06-10 | -130 |
3 | 2010-06-30 | -110 |
SELECT 3