Re: Index/trigger implementation for accessing latest records

2018-05-02 Thread Tim Cross
Alastair McKinley writes: > Hi, > > > I have a table that stores a location identifier per person which will be > appended to many times. > > However, for many queries in this system we only need to know the most recent > location per person, which is limited to about 1000 records. > > > Is th

Re: Index/trigger implementation for accessing latest records

2018-05-02 Thread Alvaro Herrera
Alastair McKinley wrote: > create function latest_record_update() returns trigger as > $$ > BEGIN > update location_records set latest_record = false where person_id = > new.person_id and latest_record is true and id != new.id; > return new; > END; > $$ language plpgsql; > > crea

Re: Index/trigger implementation for accessing latest records

2018-05-02 Thread Gavin Flower
Hi Alastair, See embedded comments. On 02/05/18 21:51, Alastair McKinley wrote: Hi, I have a table that stores a location identifier per person which will be appended to many times. However, for many queries in this system we only need to know the most recent location per person, which i

Index/trigger implementation for accessing latest records

2018-05-02 Thread Alastair McKinley
Hi, I have a table that stores a location identifier per person which will be appended to many times. However, for many queries in this system we only need to know the most recent location per person, which is limited to about 1000 records. Is the following trigger/index strategy a reasonabl