X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id A67399FA374 for ; Wed, 7 Jun 2006 02:30:14 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 30102-09 for ; Wed, 7 Jun 2006 02:30:10 -0300 (ADT) X-Greylist: delayed 00:23:38.916247 by SQLgrey- Received: from smaug.vex.net (smaug.vex.net [66.96.28.243]) by postgresql.org (Postfix) with ESMTP id ED41C9FA2BC for ; Wed, 7 Jun 2006 02:30:10 -0300 (ADT) Received: from bee.xxvii.x (H140.C18.B96.tor.eicat.ca [66.96.18.140]) by smaug.vex.net (Postfix) with ESMTP id 7FAC326B3F for ; Wed, 7 Jun 2006 01:06:28 -0400 (EDT) Received: by bee.xxvii.x (Postfix, from userid 1000) id 213651CCB0; Wed, 7 Jun 2006 01:06:30 -0400 (EDT) From: Tim Middleton Reply-To: pgsql-sql@postgresql.org Organization: xxvii.net To: pgsql-sql@postgresql.org Subject: Re: How to get list of days between two dates? Date: Wed, 7 Jun 2006 01:06:29 -0400 User-Agent: KMail/1.9.1 References: <4485EE67.5060005@kshs.org> In-Reply-To: <4485EE67.5060005@kshs.org> X-GPG-Fingerprint: F59D 8A8C A8E1 23B5 407D DD30 9069 D1B3 6416 FFB6 X-Whee: Yes, Please. MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200606070106.29950.x@vex.net> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/82 X-Sequence-Number: 25318 This is going to be ugly, and I can't even say for sure it's right (and if by chance it is right, I imagine it still might be more efficient broken up in a function), but intrigued by learning about generate_series() from Scott Marlows response I fiddled until I got the results specified like this... SELECT dt, event_name FROM ( SELECT (mn.d + s.d) AS dt FROM ( SELECT min(start_time) FROM test_events) AS mn(d), generate_series(0, ( SELECT (extract('epoch' from age(max(end_time), min(start_time)))/86400)::integer FROM test_events)) AS s(d)) AS x JOIN test_events AS y ON (dt BETWEEN start_time AND end_time) ORDER BY dt, event_name; dt | event_name ------------+-------------- 2006-05-01 | First Event 2006-05-02 | First Event 2006-05-02 | Second Event 2006-05-03 | First Event 2006-05-04 | First Event 2006-05-04 | Third Event 2006-05-05 | Third Event 2006-05-07 | Fourth Event (8 rows) -- Tim Middleton | Vex.Net | "Who is Ungit?" said he, still holding x@veX.net | VexTech.ca | my hands. --C.S.Lewis (TWHF)