add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
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 the_table ("timestamp" timestamp, tracker_id int, position int )
CREATE TABLE
insert into the_table values
('2020-02-01 21:53:45',15,1),
('2020-01-01 00:53:45',15,1),
('2020-02-01 21:53:45',11,1),
('2020-02-01 20:53:46',11,2),
('2020-02-01 18:19:20',12,4),
('2020-02-02 18:19:20',12,5);


INSERT 0 6
select distinct on (tracker_id) *
from the_table
where tracker_id in (11,12,15)
order by tracker_id, "timestamp" desc;
timestamp tracker_id position
2020-02-01 21:53:45 11 1
2020-02-02 18:19:20 12 5
2020-02-01 21:53:45 15 1
SELECT 3