X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 0FD82D1B49B for ; Fri, 4 Jun 2004 12:18:14 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 59329-04 for ; Fri, 4 Jun 2004 15:18:12 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 78C76D1CEB1 for ; Fri, 4 Jun 2004 12:18:06 -0300 (ADT) Received: (qmail 13408 invoked by uid 500); 4 Jun 2004 15:23:44 -0000 Date: Fri, 4 Jun 2004 10:23:44 -0500 From: Bruno Wolff III To: Stijn Vanroye Cc: pgsql-sql@postgresql.org Subject: Re: Difference between two times as a numeric value in a stored procedure. Message-ID: <20040604152344.GA12744@wolff.to> Mail-Followup-To: Stijn Vanroye , pgsql-sql@postgresql.org References: <736CEAA26E7E3F48943458F760E7A32603B621@fs1010.farcourier.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <736CEAA26E7E3F48943458F760E7A32603B621@fs1010.farcourier.com> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/32 X-Sequence-Number: 17977 On Fri, Jun 04, 2004 at 10:11:57 +0200, Stijn Vanroye 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.