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 tbl(
store_visited text,
virtual_time timestamp);
insert into tbl values
('M&S','2017-09-16 17:52:06'),('WholeFoods','2017-09-16 18:26:17'),
('WholeFoods','2017-09-16 18:26:19'),('WholeFoods','2017-09-16 18:26:20'),
('OysterRooms','2017-09-18 13:31:39');
select * from tbl;
5 rows affected
store_visited | virtual_time |
---|---|
M&S | 2017-09-16 17:52:06 |
WholeFoods | 2017-09-16 18:26:17 |
WholeFoods | 2017-09-16 18:26:19 |
WholeFoods | 2017-09-16 18:26:20 |
OysterRooms | 2017-09-18 13:31:39 |
select
store_visited,
virtual_time
from
(select
store_visited,
virtual_time,
row_number() over(partition by store_visited order by virtual_time asc) as vt
from
tbl) as new
where
vt = '1'
order by
virtual_time;
store_visited | virtual_time |
---|---|
M&S | 2017-09-16 17:52:06 |
WholeFoods | 2017-09-16 18:26:17 |
OysterRooms | 2017-09-18 13:31:39 |