Re: partitioning a dataset + employing hysteresis condition - Mailing list pgsql-general

From David Johnston
Subject Re: partitioning a dataset + employing hysteresis condition
Date
Msg-id C84984CE-3314-4389-9550-E517AECA1CA5@yahoo.com
Whole thread Raw
In response to Re: partitioning a dataset + employing hysteresis condition  (Gavin Flower <GavinFlower@archidevsys.co.nz>)
Responses Re: partitioning a dataset + employing hysteresis condition  (Amit Dor-Shifer <amit.dor.shifer@gmail.com>)
List pgsql-general
On Nov 15, 2011, at 15:28, Gavin Flower <GavinFlower@archidevsys.co.nz> wrote:

On 14/11/11 18:35, Amit Dor-Shifer wrote:

On Mon, Nov 14, 2011 at 4:29 PM, Amit Dor-Shifer <amit.dor.shifer@gmail.com> wrote:
Hi,
I've got this table:
create table phone_calls
(
    start_time timestamp,
    device_id integer,
    term_status integer
);

It describes phone call events. A 'term_status' is a sort-of an exit status for the call, whereby a value != 0 indicates some sort of error.
Given that, I wish to retrieve data on devices with a persisting error on them, of a specific type. I.E. that their last term_status was, say 2. I'd like to employ some hysteresis on the query: only consider a device as errorring if:
1. the last "good" (0) term_status pre-dates a "bad" (2) term_status.
2. it has at least N "bad" term_status events following the last "good" one.
3. The time span between the first "bad" term_status event and the last one is >= T minutes

For instance, w/the following data set:


Alternative thought,

Have a Boolean field which is set to true for non-zero entries and false for zeros.  Upon entering a zero into the table, for a given device, set all currently true records to false.  Combine with a partial index on the true and you can quickly get a listing of all devices in error mode and all the recent error entries.

David J.

pgsql-general by date:

Previous
From: Gavin Flower
Date:
Subject: Re: partitioning a dataset + employing hysteresis condition
Next
From: Ivan Sergio Borgonovo
Date:
Subject: Re: how to drop function?