Thread: Frequent update - how to do?

Frequent update - how to do?

From
grell
Date:
Hi,
Firstly I will tell you what I'm trying to do:
I have a database. I have a table Person. Person has location and this
location need to be updated f.e. every 5 min or with higher frequently.
Should I have some special tool, table or whatever to keep this data? I want
to have history of location so I nned to keep old values.

I'm a beginner so thank you for all advice :)



--
View this message in context: http://postgresql.1045698.n5.nabble.com/Frequent-update-how-to-do-tp5737148.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


Re: Frequent update - how to do?

From
John R Pierce
Date:
On 12/19/2012 5:44 AM, grell wrote:
> Firstly I will tell you what I'm trying to do:
> I have a database. I have a table Person. Person has location and this
> location need to be updated f.e. every 5 min or with higher frequently.
> Should I have some special tool, table or whatever to keep this data? I want
> to have history of location so I nned to keep old values.


so you don't just want location for each person, you want their entire
path?  5 minute intervals will accumulate almost 9000 locations a month
for each person.   how many 'persons' in the table ?

if this location data is latitude/longitude, I'd consider using the
PostGIS extension for storing it. I think I'd store locations in a
separate table, with (person_id integer, ts timestamptz, location
geography(POINT))

and insert each position in there.

to get the info on person $1 including his current location....

    select p.*, l.location
         from persons p join locations l on p.id=l.person_id
         where p.id=$1
         order by l.timestamptz desc limit 1;

to get person $1's path...

     select ts,location from locations where person_id=$1 order by ts;

etc etc.