Re: [GENERAL] Select ranges based on sequential breaks

2009-06-22 Thread Joel Nothman
On Tue, 23 Jun 2009 04:41:44 +1000, Mike Toews wrote: Window functions appear to be the best solution for this style of problem, and I'm looking forward to their applications. However, I'm sticking with 8.3 for at least a year, so I'm not able to explore this solution yet. For now, I can on

Re: [GENERAL] Select ranges based on sequential breaks

2009-06-22 Thread Mike Toews
Scott Marlowe wrote: On Mon, Jun 15, 2009 at 12:23 PM, Mike Toews wrote: This is easy to compute using a spreadsheet or in R, but how would I do this with SQL? I'm using 8.3. Advice is appreciated. FYI (and I'm no expert in this area) R is available as a pl for postgres, look for pl/R

Re: [GENERAL] Select ranges based on sequential breaks

2009-06-22 Thread Scott Marlowe
On Mon, Jun 22, 2009 at 12:41 PM, Mike Toews wrote: > Hi Joel, > An excellent book that I recently stumbled on is /Joe Celko's SQL for > Smarties/ (recommended by someone on this list), which is a heavy read, but > has an amazing depth to ANSI SQL. Of particular interest is "Chapter 24: > Regions,

Re: [GENERAL] Select ranges based on sequential breaks

2009-06-22 Thread Mike Toews
Hi Joel, Window functions appear to be the best solution for this style of problem, and I'm looking forward to their applications. However, I'm sticking with 8.3 for at least a year, so I'm not able to explore this solution yet. For now, I can only post-process the output in a non-SQL environ

Re: [GENERAL] Select ranges based on sequential breaks

2009-06-22 Thread Scott Marlowe
On Mon, Jun 15, 2009 at 12:23 PM, Mike Toews wrote: > This is easy to compute using a spreadsheet or in R, but how would I do this > with SQL? I'm using 8.3. Advice is appreciated. FYI (and I'm no expert in this area) R is available as a pl for postgres, look for pl/R or plR -- Sent via pgsql-ge

Re: [GENERAL] Select ranges based on sequential breaks

2009-06-22 Thread Joel Nothman
Hi Mike, I happened upon your query, which is related to some stuff I've been playing with. Firstly, David's solution below doesn't work. I haven't yet tried to work out why. Secondly, I was hoping to be able to solve your problem nicely with Postgres 8.4's window functions [1,2], which provide

Re: [GENERAL] Select ranges based on sequential breaks

2009-06-22 Thread Joel Nothman
Hi Mike, I happened upon your query, which is related to some stuff I've been playing with. Firstly, David's solution below doesn't work. I haven't yet tried to work out why. Secondly, I was hoping to be able to solve your problem nicely with Postgres 8.4's window functions [1,2], which can prov

Re: [GENERAL] Select ranges based on sequential breaks

2009-06-15 Thread David Wilson
On Mon, Jun 15, 2009 at 2:23 PM, Mike Toews wrote: > Hi, > > I'm having difficulty constructing a query that will find breaks where data > change in a time-series. I've done some searching for this too, but I > haven't found anything. > > Here is my example situation, consider my source table: > da

[GENERAL] Select ranges based on sequential breaks

2009-06-15 Thread Mike Toews
Hi, I'm having difficulty constructing a query that will find breaks where data change in a time-series. I've done some searching for this too, but I haven't found anything. Here is my example situation, consider my source table: datebin 2009-01-01 red 2009-01-02 red 2009-01-03