![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I am trying to group track positions from a ship into sections split by gaps of no recorded position from a particular ship for a period of time (say 60 minutes). |
#3
| |||
| |||
|
|
Could you assume that role and explain "for idiots" what you are trying to achieve? Yours, Laurenz Albe |
|
',lastKey,lastTime cu.execute('INSERT INTO transit |
#4
| |||
| |||
|
|
I am trying to group into a series of runs where the runs are separated by periods when there are no received points for 60 minutes. Does that make any sense? select key,userid,cg_sec,cg_timestamp from oneShip; key | userid | cg_sec | cg_timestamp -----+-----------+------------+--------------------- 251 | 366725230 | 1178661410 | 2007-05-08 21:56:50 252 | 366725230 | 1178661421 | 2007-05-08 21:57:01 253 | 366725230 | 1178661561 | 2007-05-08 21:59:21 254 | 366725230 | 1178661710 | 2007-05-08 22:01:50 255 | 366725230 | 1178661900 | 2007-05-08 22:05:00 256 | 366725230 | 1178661940 | 2007-05-08 22:05:40 257 | 366725230 | 1178663311 | 2007-05-08 22:28:31 258 | 366725230 | 1178663360 | 2007-05-08 22:29:20 259 | 366725230 | 1178663441 | 2007-05-08 22:30:41 260 | 366725230 | 1178663540 | 2007-05-08 22:32:20 -- here is the time jump between the two that I need to split on 266 | 366725230 | 1178729461 | 2007-05-09 16:51:01 267 | 366725230 | 1178730221 | 2007-05-09 17:03:41 (12 rows) Where the results should be this for the separated transits: userid | startKey | endKey 366725230 | 251 | 260 366725230 | 266 | 267 |
#5
| |||
| |||
|
|
This query definitely does NOT perform well, as it will execute several sequential scans on the table, but it should produce what you want (there may be errors if the time gap is exactly 60 minutes, but fixing those is left as an exercise to the reader): SELECT ship1.key AS startkey, ship2.key AS endkey .... I would recommend to not code this as an SQL query because it can be done much easier and with better performance as a function RETURNS SETOF oneShip in PL/pgSQL or any language of your choice. Yours, Laurenz Albe |
![]() |
| Thread Tools | |
| Display Modes | |
| |