From: A. Kretschmer <andreas.kretschmer@schollglas.com>
To: pgsql-sql@postgresql.org
Subject: Re: Check set of date intervals
Date: Thu, 27 May 2010 14:45:15 +0200
Message-ID: <20100527124515.GE6907@a-kretschmer.de> (raw)
In-Reply-To: <AANLkTikOY8cER1UOQXxHdcUXJYOB0nuK-3A9CxiLGsfB@mail.gmail.com>
References: <AANLkTil8uYMMxel-SmWLDEuHPu0l2DHM0CjetnxAX3GL@mail.gmail.com>
<20100527102713.GC6907@a-kretschmer.de>
<20100527104336.GD6907@a-kretschmer.de>
<AANLkTikOY8cER1UOQXxHdcUXJYOB0nuK-3A9CxiLGsfB@mail.gmail.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: andreas.kretschmer@schollglas.com
Subject: Re: Check set of date intervals
In-Reply-To: <20100527124515.GE6907@a-kretschmer.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox