Re: Statistical aggregates with intervals

From: Christopher Swingley <cswingle(at)gmail(dot)com>
To: Thomas Munro <munro(at)ip9(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Statistical aggregates with intervals
Date: 2012-08-23 21:39:11
Message-ID: CAHsw44-mWjPm=1WaeuU35BAZi1ouoyDngTwQpzaKeDRA1oCwww@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thomas,

On Wed, Aug 22, 2012 at 12:25 PM, Thomas Munro <munro(at)ip9(dot)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(at)gmail(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joe Conway 2012-08-23 21:58:52 Re: need substring based on delimiter
Previous Message Gauthier, Dave 2012-08-23 21:30:33 need substring based on delimiter