From: | Ondrej Ivanič <ondrej(dot)ivanic(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org, Christopher Swingley <cswingle(at)gmail(dot)com> |
Subject: | Re: Statistical aggregates with intervals |
Date: | 2012-08-23 22:43:53 |
Message-ID: | CAM6mieKEcFnidnQDWG7o+QE1Bi+6eBTPLEMisa4kB2Se6A8Rrw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi,
On 24 August 2012 07:39, Christopher Swingley <cswingle(at)gmail(dot)com> wrote:
> 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;
Looks complicated. You can extract 'epoch':
db=# select now() - (now() - interval '1 day');
?column?
----------
1 day
(1 row)
db=# select extract(epoch from (now() - (now() - interval '1 day')));
date_part
-----------
86400
(1 row)
--
Ondrej Ivanic
(ondrej(dot)ivanic(at)gmail(dot)com)
From | Date | Subject | |
---|---|---|---|
Next Message | Jeff Janes | 2012-08-24 00:16:01 | Re: At what point does a big table start becoming too big? |
Previous Message | Joe Conway | 2012-08-23 21:58:52 | Re: need substring based on delimiter |