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 C13FF9FB1B9 for ; Tue, 6 Jun 2006 18:22:34 -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 60607-01 for ; Tue, 6 Jun 2006 18:22:29 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from exchange.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id EEA1D9FA13E for ; Tue, 6 Jun 2006 18:22:29 -0300 (ADT) Received: from 10.10.1.37 ([10.10.1.37]) by exchange.g2switchworks.com ([10.10.1.2]) with Microsoft Exchange Server HTTP-DAV ; Tue, 6 Jun 2006 21:22:22 +0000 Received: from state.g2switchworks.com by mail.g2switchworks.com; 06 Jun 2006 16:22:22 -0500 Subject: Re: How to get list of days between two dates? From: Scott Marlowe To: Aaron Bono Cc: Christine Desmuke , pgsql-sql@postgresql.org In-Reply-To: References: <4485EE67.5060005@kshs.org> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1149628942.25526.232.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Tue, 06 Jun 2006 16:22:22 -0500 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/75 X-Sequence-Number: 25311 On Tue, 2006-06-06 at 16:17, Aaron Bono wrote: > Though there may be a more eligant way to do it, when we did things > like this in the past we created a function (or stored procedure) that > got the min and max dates and then created a result set that iterated > through the dates to create a virtual table of days. Then you can > inner join that list of days with your physical table. If you're on a version of pgsql with generate_series, you can use that to easily create a pivoting data set on the fly to do this. If you're on an older version, it's easy enough to make a generic pivot table and keep it around to do these things. Since we're still on 7.4 where I work, we use the pre-populated pivot table. It's primitive, but it works.