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 objects (object_id int
, city_id int , price DECIMAL(10,2), area_total int , status varchar(10), class varchar(10)
, action varchar(10), date_create timestamp)
INSERT INTO objects (object_id, city_id, price, area_total, status, class, action, date_create) VALUES (1, 1, 4600000, 72, 'active', 'Вторичная', 'Продажа', '2020-11-18 12:23:00');
INSERT INTO objects (object_id, city_id, price, area_total, status, class, action, date_create) VALUES (2, 2, 5400000, 84, 'active', 'Secondary', 'Sale', '2020-11-19 21:49:35');
1 rows affected
1 rows affected
SELECT
object_id,
date_trunc('week', date_create)::timestamp AS "Monday",
(date_trunc('week', date_create)+ '6 days'::interval)::timestamp As "Sunday",
date_trunc('week', date_create)::timestamp
|| ' - '
|| (date_trunc('week', date_create)+ '6 days'::interval)::timestamp AS "range"
FROM objects
object_id | Monday | Sunday | range |
---|---|---|---|
1 | 2020-11-16 00:00:00 | 2020-11-22 00:00:00 | 2020-11-16 00:00:00 - 2020-11-22 00:00:00 |
2 | 2020-11-16 00:00:00 | 2020-11-22 00:00:00 | 2020-11-16 00:00:00 - 2020-11-22 00:00:00 |