Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 0BF8F632777 for ; Thu, 27 May 2010 09:45:26 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 91831-06 for ; Thu, 27 May 2010 12:45:17 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.171]) by mail.postgresql.org (Postfix) with ESMTP id DAAA1632755 for ; Thu, 27 May 2010 09:45:18 -0300 (ADT) Received: from webserv.wug.de ([194.25.154.138]) by mrelayeu.kundenserver.de (node=mreu0) with ESMTP (Nemesis) id 0MDTuj-1O1NB32m6P-00GftW; Thu, 27 May 2010 14:45:17 +0200 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1OHcSZ-0001yW-00 for pgsql-sql@postgresql.org; Thu, 27 May 2010 14:45:15 +0200 Date: Thu, 27 May 2010 14:45:15 +0200 From: "A. Kretschmer" To: pgsql-sql@postgresql.org Subject: Re: Check set of date intervals Message-ID: <20100527124515.GE6907@a-kretschmer.de> References: <20100527102713.GC6907@a-kretschmer.de> <20100527104336.GD6907@a-kretschmer.de> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-OS: Debian/GNU Linux - weil ich es mir Wert bin! User-Agent: Mutt/1.5.9i X-Provags-ID: V01U2FsdGVkX1+KKsoQcyeAWc2kfo91LhpdUsQM6ACVp7RFKIJ gnRI5W9tnTg0OvM1Wvoi6ANrc7HM/pDXBswWuqDknOgT0NbMSK 7o7NO3H+eNKHD7ayw0FDw== X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.81 tagged_above=-5 required=5 tests=BAYES_50=0.8, RCVD_IN_DNSWL_NONE=-0.0001, T_FRT_CONTACT=0.01 X-Spam-Level: X-Archive-Number: 201005/125 X-Sequence-Number: 34173 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