Technique for turning time ranges into a graph - Mailing list pgsql-sql

From Bryce Nesbitt
Subject Technique for turning time ranges into a graph
Date
Msg-id 467A06BC.6090900@obviously.com
Whole thread Raw
Responses Re: Technique for turning time ranges into a graph  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
List pgsql-sql
I have a bunch of data which is expressed in terms of start and stop dates, e.g.:<br /><br /><table border="1"
cellpadding="2"cellspacing="2" height="112" width="460"><tbody><tr><td valign="top"><b>Member<br /></b></td><td
valign="top"><b>Start<br/></b></td><td valign="top"><b>Stop<br /></b></td></tr><tr><td valign="top">Fred<br /></td><td
valign="top">2007-01-01<br/></td><td valign="top">2007-05-01<br /></td></tr><tr><td valign="top">Joe<br /></td><td
valign="top">2005-05-04<br/></td><td valign="top">2007-04-01<br /></td></tr><tr><td valign="top">Freddie<br /></td><td
valign="top">2002-02-01<br/></td><td valign="top">2006-04-01<br /></td></tr><tr><td valign="top">...<br /></td><td
valign="top">...<br/></td><td valign="top">...<br /></td></tr></tbody></table><br /> And what I want is a graph over
timeshowing the number of members on each day.<br /><br /> Thus the input is rows with time ranges, and the output is a
scalarfor each time bucket.  The time bucket might be months, days, hours, or quarter hours. Such a data series could
thenbe loaded into a spreadsheet or otherwise graphed.<br /><br /> I've got a perl script that can do this.  But is
therea good and fast way to do this in the database?  If I had views with the scalar data, then I could do some more
interestingjoining like comparing member growth to advertising dollars spent, or calculating the ratios between members
andcustomer service calls.<br /><br /> It seems like a lot of data is inherently stored as time ranges.  How would you
queryand manipulate such data?<br /><pre class="moz-signature" cols="100">-- 
 
----
Visit <a href="http://www.obviously.com/">http://www.obviously.com/</a>
</pre>

pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Constraint exclusion
Next
From: "A. Kretschmer"
Date:
Subject: Re: Technique for turning time ranges into a graph