Re: gaps/overlaps in a time table : current and previous row question

Поиск
Список
Период
Сортировка
От
Тема Re: gaps/overlaps in a time table : current and previous row question
Дата
Msg-id 29F36C7C98AB09499B1A209D48EAA615B7653DBDF9@mail2a.alliedtesting.com
обсуждение исходный текст
Ответ на gaps/overlaps in a time table : current and previous row question  (thomas veymont <thomas.veymont@gmail.com>)
Ответы Re: gaps/overlaps in a time table : current and previous row question  (thomas veymont <thomas.veymont@gmail.com>)
Список pgsql-general
> -----Original Message-----
> From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-
> owner@postgresql.org] On Behalf Of thomas veymont
> Sent: Wednesday, October 05, 2011 5:35 PM
> To: pgsql-general@postgresql.org
> Subject: [GENERAL] gaps/overlaps in a time table : current and previous row
> question
> 
> 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 ? 

You can't. The order in which rows are retrieved  from a table is undefined, unless you specify it in your query. If
theindex cannot be used to specify the order, then there is no way for you to retrieve rows in the "correct" order.
 

If you could get the rows in the correct order, you could use the lag() window function to do what you want.

В списке pgsql-general по дате отправления:

Предыдущее
От: "Albe Laurenz"
Дата:
Сообщение: Re: function "XXX" already exists with same argument types
Следующее
От: Raymond O'Donnell
Дата:
Сообщение: Re: problem with round() in php script