Search Postgresql Archives

Re: Statistical aggregates with intervals

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 24 August 2012 07:39, Christopher Swingley <cswingle@xxxxxxxxx> 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.ivanic@xxxxxxxxx)


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux