I'm using a small collection of webscrapers to get the current GPS location of various devices. I also want to keep historic records. What's the best way of doing this without storing the data twice? For now i have two tables, both looking like this:
Column | Type | Modifiers | Storage | Description
---------+-----------------------------+---------------+----------+-------------
vehicle | character varying(20) | | extended |
course | real | | plain |
speed | real | | plain |
fix | smallint | | plain |
lat | real | | plain |
lon | real | | plain |
time | timestamp without time zone | default now() | plain |
One is named gps
, and another is named gps_log
. The function that updates these two does two things: first it performs an INSERT
on gps_log
, and afterwards it does an UPDATE OR INSERT
(a user-defined function) on gps
. However, this results in what seems to me as a pointless case of double-storing for other purposes than having easy SELECT
able access to the current data.
Is there a simple way of only using gps_log
and having a function select only the newest entry for each vehicle
? Keep in mind that gps_log
currently has 1397150 rows increasing with roughly 150 rows every 15 minutes, so performance is likely to be an issue.
Using PostgreSQL 8.4 via Perl DBI.