Re: [SQL] merge timestamps to intervals

2008-05-11 Thread Craig Ringer
Patrick Scharrenberg wrote: > I'd like to merge this information to intervals where the service was up > or down. > > < intervall, status > > 10:13-10:15 up > 10:16-10:16 down > 10:17-1018 up > > I've no clue how to approach this problem. About 12 hours ago

[SQL] merge timestamps to intervals

2008-05-11 Thread Patrick Scharrenberg
Hi! I have a table where I repeatingly log the status of some service, which looks something like this: < timestamp, status > Now, everytime my service is up I save the timestamp and a status of "up", if it's down I save the timestamp with "down", eg: 10:13 up 10:14 u

Re: [SQL] Difference in columns

2008-05-11 Thread Mag Gam
Thanks all. I will try some of these suggestions. On Sun, May 11, 2008 at 3:58 PM, Craig Ringer <[EMAIL PROTECTED]> wrote: > Mag Gam wrote: > > > I am trying to find the difference between the size column. So the > > desired output would be > > > >ts | size| Diff > > ---

Re: [SQL] Difference in columns

2008-05-11 Thread Craig Ringer
Mag Gam wrote: > I am trying to find the difference between the size column. So the > desired output would be > >ts | size| Diff > ---+-+-- > 2002-03-16| 11 | 0 > > 2002-03-17| 15 | 4 > 2002-03-18| 18 | 3 > 2002-03-19

Re: [SQL] Difference in columns

2008-05-11 Thread Tom Lane
"Gurjeet Singh" <[EMAIL PROTECTED]> writes: > On Sun, May 11, 2008 at 11:47 PM, Craig Ringer <[EMAIL PROTECTED]> >> If you cannot assume that, you can use a subquery with limit and order >> by to obtain the next record: >> >> SELECT >> a.ts, >> (SELECT b.size FROM x b WHERE b.ts > a.ts ORDER BY b.

Re: [SQL] Difference in columns

2008-05-11 Thread Gurjeet Singh
On Sun, May 11, 2008 at 11:47 PM, Craig Ringer <[EMAIL PROTECTED]> wrote: > Mag Gam wrote: > > > > >ts | size| Diff > > ---+-+-- > > 2002-03-16| 11 | 0 > > > > 2002-03-17| 15 | 4 > > 2002-03-18| 18 | 3 > > 2002-03-19|

Re: [SQL] Difference in columns

2008-05-11 Thread Craig Ringer
Mag Gam wrote: > >ts | size| Diff > ---+-+-- > 2002-03-16| 11 | 0 > > 2002-03-17| 15 | 4 > 2002-03-18| 18 | 3 > 2002-03-19| 12 | -6 > > > I need the first column to be 0, since it will be 11-11. The second > colum

Re: [SQL] Difference in columns

2008-05-11 Thread hubert depesz lubaczewski
On Sun, May 11, 2008 at 01:37:52PM -0400, Mag Gam wrote: > Any thoughts about this? 1. will there be any gaps in between dates? if yes, what should be diff be then? 2. can't you calculate it in client application? 3. is usage of pl/pgsql acceptable (i think this will be the fastest way to do it in

Re: [SQL] Difference in columns

2008-05-11 Thread Gurjeet Singh
On Sun, May 11, 2008 at 11:07 PM, Mag Gam <[EMAIL PROTECTED]> wrote: > Hi All, > > I have a view that generates output similar to this. > > select * from foo.view; > >ts | size > ---+- > 2002-03-16| 11 > 2002-03-17| 16 > > 2002-03-18|

Re: [SQL] Difference in columns

2008-05-11 Thread chester c young
--- Mag Gam <[EMAIL PROTECTED]> wrote: > Hi All, > > I have a view that generates output similar to this. > > select * from foo.view; > >ts | size > ---+- > 2002-03-16| 11 > 2002-03-17| 16 > 2002-03-18| 18 > 2002-03-19| 1

[SQL] Difference in columns

2008-05-11 Thread Mag Gam
Hi All, I have a view that generates output similar to this. select * from foo.view; ts | size ---+- 2002-03-16| 11 2002-03-17| 16 2002-03-18| 18 2002-03-19| 12 I am trying to find the difference between the size column. So