Re: Finding date intersections
От | David G Johnston |
---|---|
Тема | Re: Finding date intersections |
Дата | |
Msg-id | 1414173779425-5824194.post@n5.nabble.com обсуждение исходный текст |
Ответ на | Re: Finding date intersections (John McKown <john.archie.mckown@gmail.com>) |
Ответы |
Re: Finding date intersections
|
Список | pgsql-general |
John McKown wrote >> insert into sales values >> (tstzrange('2014-1-1', '2014-1-2')), >> (tstzrange('2014-1-2', '2014-1-3')), >> (tstzrange('2014-1-2', '2014-1-4')), >> (tstzrange('2014-1-5', '2014-1-6')); >> >> -- want back: >> -- tstzrange('2014-1-1', '2014-1-4') >> -- tstzrange('2014-1-6', '2014-1-6') >> I presume the second output row should be [5,6)... And why are you using a timestamp range when your data are dates? My first thought is to explode the ranges into distinct dates, order them inside a window, use lag(...) to find breaks,p and assign groups, the for each group take the min and max of the group and form a new range. Not sure exactly what the SQL looks like - especially the range explosion - but should technically work even though performance may suck. Probably want to use lateral and generate_series(...) if you are on a more recent version. David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/Finding-date-intersections-tp5824102p5824194.html Sent from the PostgreSQL - general mailing list archive at Nabble.com.
В списке pgsql-general по дате отправления: