Re: How to get list of days between two dates?

From: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>
To: Aaron Bono <postgresql(at)aranya(dot)com>
Cc: Christine Desmuke <cdesmuke(at)kshs(dot)org>, pgsql-sql(at)postgresql(dot)org
Subject: Re: How to get list of days between two dates?
Date: 2006-06-06 21:22:22
Message-ID: 1149628942.25526.232.camel@state.g2switchworks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Broersma Jr 2006-06-06 22:13:37 Re: How To Exclude True Values
Previous Message Aaron Bono 2006-06-06 21:17:19 Re: How to get list of days between two dates?