Re: Statistical aggregates with intervals - Mailing list pgsql-general

From Christopher Swingley
Subject Re: Statistical aggregates with intervals
Date
Msg-id CAHsw44-mWjPm=1WaeuU35BAZi1ouoyDngTwQpzaKeDRA1oCwww@mail.gmail.com
Whole thread Raw
In response to Statistical aggregates with intervals  (Thomas Munro <munro@ip9.org>)
Responses Re: Statistical aggregates with intervals  (Ondrej Ivanič <ondrej.ivanic@gmail.com>)
List pgsql-general
Thomas,

On Wed, Aug 22, 2012 at 12:25 PM, Thomas Munro <munro@ip9.org> wrote:
> I noticed that 'avg' works on 'interval', but 'stddev' and 'variance' don't:

I don't know why, but you could convert 'interval' into something else
where all the functions work:

CREATE OR REPLACE FUNCTION interval_to_seconds(interval)
RETURNS double precision AS $$
    SELECT (extract(days from $1) * 86400)
         + (extract(hours from $1) * 3600)
         + (extract(minutes from $1) * 60)
         + extract(seconds from $1);
$$ LANGUAGE SQL;

Cheers,

Chris
--
Christopher Swingley
Fairbanks, Alaska
http://swingleydev.com/
cswingle@gmail.com


pgsql-general by date:

Previous
From: "Gauthier, Dave"
Date:
Subject: need substring based on delimiter
Next
From: Joe Conway
Date:
Subject: Re: need substring based on delimiter