self join for history analyzis - Mailing list pgsql-general

From Rafał Pietrak
Subject self join for history analyzis
Date
Msg-id 5103CCC4.5030900@zorro.isa-geek.com
Whole thread Raw
Responses Re: self join for history analyzis
List pgsql-general
Hello the list,

For some time now, I'm struggling with a problem of self join of a table:

I have a usage recording table: CREATE TABLE readings(tm timestamp,
bytesin int, bytesout int);

The readouts are made "occasionally" - the timespan between the readouts
are not very precise, but there is a lot of those readouts.

I need to make a self join of that table to analyze the bandwidth usage
e.g.: when presenting data, for every readout I need to compute the
difference between it and the one immediately preceding it, and divide
that by respective measurement interval.

Initially I've put an additional column with a serial into the readouts
table, and did a join on (p.serial = n.serial+1); but that had an
occasional glitch, when serial actually skipped a value. So I'm trying
to work out a more resiliant/general solution. So far to no avail.

Is there an "sql-idiom" (receipt?) to do such join? the better if
without the spurious seiral column.

Thenx


-R


pgsql-general by date:

Previous
From: Gavan Schneider
Date:
Subject: Re: Throttling Streamming Replication
Next
From: Alban Hertroys
Date:
Subject: Re: self join for history analyzis