Re: Check set of date intervals

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Check set of date intervals
Date: 2010-05-27 12:45:15
Message-ID: 20100527124515.GE6907@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

In response to Anton Gavazuk :
> Hi Andreas,
>
> great thanks for the response,

please, answer to the list, not to me, okay?

>
> unfortunately function just tests every row  - it doesnt construct set of
> periods which would cover choosed period.

That's hard to achieve ... maybe you have to create a table with
contiguous periods. Somewhere i have found this code-snippet:

test=*# select * from t1;
a
----
1
2
3
4
6
7
8
10
11
12
13
(11 rows)

test=*# WITH RECURSIVE RecCols (LeftBoundary, Value) AS
(SELECT a, a FROM t1 WHERE (a - 1) NOT IN (SELECT a FROM t1)
UNION ALL SELECT p.LeftBoundary, c.a FROM RecCols AS p, t1 AS c WHERE c.a = p.Value + 1)
SELECT LeftBoundary, MAX(Value) AS RightBoundary FROM RecCols
GROUP BY LeftBoundary
ORDER BY LeftBoundary;
leftboundary | rightboundary
--------------+---------------
1 | 4
6 | 8
10 | 13
(3 rows)

Maybe that's the way you have to go ...

Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message James Kitambara 2010-05-27 13:55:21 Fw: Re: help
Previous Message A. Kretschmer 2010-05-27 10:43:36 Re: Check set of date intervals