Re: Getting interval in seconds?

Lists: pgsql-general
From: Lincoln Yeoh <lyeoh(at)pop(dot)jaring(dot)my>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Getting interval in seconds?
Date: 2001-06-10 02:05:51
Message-ID: 3.0.5.32.20010610100551.00feeaf0@192.228.128.13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hi,

How do I convert an interval to the number of seconds?

e.g. I'd like the following to produce a result in seconds.

select ('now'::timestamp - somedate)::interval from sometable;

Thanks,
Link.


From: Lincoln Yeoh <lyeoh(at)pop(dot)jaring(dot)my>
To: Alex Pilosov <alex(at)pilosoft(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Getting interval in seconds?
Date: 2001-06-10 03:47:04
Message-ID: 3.0.5.32.20010610114704.00fea960@192.228.128.13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Thanks!

Which is better/faster?

select date_part('epoch',('now'::timestamp - somedate)::interval) from
sometable;

Or

select extract (epoch from interval ('now'::timestamp - somedate)) from
sometable;

Should I be using 'now'::timestamp or some function form of it?

Cheerio,
Link.

At 10:34 PM 10-06-2001 -0400, Alex Pilosov wrote:
>On Sun, 10 Jun 2001, Lincoln Yeoh wrote:
>
>> Hi,
>>
>> How do I convert an interval to the number of seconds?
>>
>> e.g. I'd like the following to produce a result in seconds.
>>
>> select ('now'::timestamp - somedate)::interval from sometable;
>
>select date_part('epoch',('now'::timestamp - somedate)::interval) from
>sometable;
>
>-alex
>
>
>


From: Alex Pilosov <alex(at)pilosoft(dot)com>
To: Lincoln Yeoh <lyeoh(at)pop(dot)jaring(dot)my>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Getting interval in seconds?
Date: 2001-06-11 02:34:52
Message-ID: Pine.BSO.4.10.10106102234210.17529-100000@spider.pilosoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Sun, 10 Jun 2001, Lincoln Yeoh wrote:

> Hi,
>
> How do I convert an interval to the number of seconds?
>
> e.g. I'd like the following to produce a result in seconds.
>
> select ('now'::timestamp - somedate)::interval from sometable;

select date_part('epoch',('now'::timestamp - somedate)::interval) from
sometable;

-alex


From: Alex Pilosov <alex(at)pilosoft(dot)com>
To: Lincoln Yeoh <lyeoh(at)pop(dot)jaring(dot)my>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Getting interval in seconds?
Date: 2001-06-11 04:01:04
Message-ID: Pine.BSO.4.10.10106102359150.17529-100000@spider.pilosoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Sun, 10 Jun 2001, Lincoln Yeoh wrote:

> Thanks!
>
> Which is better/faster?
>
> select date_part('epoch',('now'::timestamp - somedate)::interval) from
> sometable;
>
> Or
>
> select extract (epoch from interval ('now'::timestamp - somedate)) from
> sometable;
Speedwise, I think its the same. _maybe_ the latter is faster, but I
wouldn't bet on it.

> Should I be using 'now'::timestamp or some function form of it?
No difference whether you use now() or 'now'::timestamp.

-alex