From: Bruno Wolff III <bruno@wolff.to>
To: Stijn Vanroye <s.vanroye@Farcourier.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Difference between two times as a numeric value in a stored procedure.
Date: Fri, 4 Jun 2004 10:23:44 -0500
Message-ID: <20040604152344.GA12744@wolff.to> (raw)
In-Reply-To: <736CEAA26E7E3F48943458F760E7A32603B621@fs1010.farcourier.com>
References: <736CEAA26E7E3F48943458F760E7A32603B621@fs1010.farcourier.com>
On Fri, Jun 04, 2004 at 10:11:57 +0200,
Stijn Vanroye <s.vanroye@Farcourier.com> wrote:
> The working of the functions is not the problem, but the return type is. I can't seem to find a way to substract two time values (or timestamp values) and get a numeric/float value. I always get the INTERVAL datatype. For example, in stead of 4:30 i would like 4.5 as a result. I have searched the documentation but could not find any way to substract time/timestamp values and get a numeric/float as a result. When I try to CAST the interval to a numeric or float value I get an error (cannot cast time without tz to ...). Same goes for trying to cast the beginvalues and then substract them. Does anyone have any idea how I can solve/circumvent this problem? Is there a function I can use?
You can use EXTRACT to extract the EPOCH from the interval which will
be the number of seconds in the interval. You can then use arithmetic
(/60.) on that number to get fractional hours.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: bruno@wolff.to, s.vanroye@Farcourier.com
Subject: Re: Difference between two times as a numeric value in a stored procedure.
In-Reply-To: <20040604152344.GA12744@wolff.to>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox