gaps/overlaps in a time table : current and previous row question - Mailing list pgsql-general

From thomas veymont
Subject gaps/overlaps in a time table : current and previous row question
Date
Msg-id CAHcTkqqHCwFjw0OyojmnzZWtTaNhFgDNc9_UHSb6Mn+8DR0C0A@mail.gmail.com
Whole thread Raw
Responses Re: gaps/overlaps in a time table : current and previous row question  (Filip Rembiałkowski <plk.zuber@gmail.com>)
Re: gaps/overlaps in a time table : current and previous row question  (<depstein@alliedtesting.com>)
Re: gaps/overlaps in a time table : current and previous row question  (Jeff Davis <pgsql@j-davis.com>)
List pgsql-general
hello,

let's say that each rows in a table contains a start time and a end
time ("timeinterval" type),
but the index are not ordered nor consecutive, e.g :

$ select * from T order by starttime

index  | starttime    |   endtime
---------+-----------------+-----------------
3        |   t1             |  t2
1        |   t3             |  t4
18      |   t5             |  t6
12      |   t7             |  t8

I want a result that shows time gaps and overlaps in this table, that is :

delta
---------+
t3 - t2 |
t5 - t4 |
t7 - t6 |

how would I do that ? I guess this could be done with window function and lag()
function but I don't know exactly how. Any suggestion ?

thanks





I guess my question is more about

pgsql-general by date:

Previous
From: Raymond O'Donnell
Date:
Subject: Re: Postgresql-8.2 Replication
Next
From: Phil Couling
Date:
Subject: Re: how to select one column into another in same table?